10 releases (6 breaking)

0.7.1 Feb 16, 2019
0.7.0 Nov 24, 2018
0.6.2 Feb 26, 2018
0.6.1 Aug 20, 2017
0.5.0 Mar 11, 2017

#7 in #colorize

Download history 25/week @ 2024-08-24 21/week @ 2024-08-31 17/week @ 2024-09-07 17/week @ 2024-09-14 53/week @ 2024-09-21 33/week @ 2024-09-28 18/week @ 2024-10-05 17/week @ 2024-10-12 17/week @ 2024-10-19 20/week @ 2024-10-26 34/week @ 2024-11-02 3/week @ 2024-11-09 8/week @ 2024-11-16 25/week @ 2024-11-23 22/week @ 2024-11-30 66/week @ 2024-12-07

122 downloads per month
Used in 8 crates (7 directly)

MIT license

15KB
354 lines

json-color - A Rust library to colorize JSON strings

Usage

Add json-color to your Cargo.toml as usual.

Examples

If you don't care about the specific colors used:

extern crate json_color;

use json_color::Colorizer;

fn main() {
    let colorizer = Colorizer::arbitrary();

    if let Ok(json_str) = colorizer.colorize_json_str("{ \"foo\": [1, 2.0, false, null] }") {
        println!("{}", json_str);
    }
}

If you want to pick specific colors to use:

extern crate json_color;

use json_color::{Colorizer, Color};

fn main() {
    let colorizer = Colorizer::new()
            .null(Color::Cyan)
            .boolean(Color::Yellow)
            .number(Color::Magenta)
            .string(Color::Green)
            .key(Color::Blue)
            .build();

    if let Ok(json_str) = colorizer.colorize_json_str("{ \"foo\": [1, 2.0, false, null] }") {
        println!("{}", json_str);
    }
}

Documentation

Hosted at docs.rs.

Dependencies

~1.3–8.5MB
~74K SLoC