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

#3 in #colorize

Download history 12/week @ 2024-02-04 27/week @ 2024-02-11 30/week @ 2024-02-18 38/week @ 2024-02-25 34/week @ 2024-03-03 42/week @ 2024-03-10 41/week @ 2024-03-17 33/week @ 2024-03-24 68/week @ 2024-03-31 28/week @ 2024-04-07 35/week @ 2024-04-14 45/week @ 2024-04-21 41/week @ 2024-04-28 39/week @ 2024-05-05 34/week @ 2024-05-12 36/week @ 2024-05-19

158 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.2–9MB
~74K SLoC