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

#97 in #color

Download history 47/week @ 2021-05-28 16/week @ 2021-06-04 43/week @ 2021-06-11 24/week @ 2021-06-18 34/week @ 2021-06-25 28/week @ 2021-07-02 42/week @ 2021-07-09 35/week @ 2021-07-16 21/week @ 2021-07-23 72/week @ 2021-07-30 74/week @ 2021-08-06 26/week @ 2021-08-13 24/week @ 2021-08-20 85/week @ 2021-08-27 4/week @ 2021-09-03 25/week @ 2021-09-10

181 downloads per month
Used in less than 7 crates

MIT license

14KB
368 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–1.3MB
~27K SLoC