json-color

Crates.iojson-color
lib.rsjson-color
version0.7.1
sourcesrc
created_at2017-01-05 02:25:43.732452
updated_at2019-02-16 01:19:43.913882
descriptionColorize JSON strings
homepagehttps://github.com/saghm/json-color.git
repositoryhttps://github.com/saghm/json-color.git
max_upload_size
id7932
size14,359
Saghm Rossi (saghm)

documentation

https://docs.rs/json-color

README

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.

Commit count: 31

cargo fmt