#json #colored #color #colour #coloured

colored_json

Colorize JSON, for printing it out on the command line

15 releases (5 stable)

3.0.1 Sep 19, 2022
2.1.0 Nov 4, 2019
2.0.0 Feb 1, 2019
1.0.0 Dec 5, 2018
0.6.2 Nov 30, 2018

#24 in Command-line interface

Download history 1403/week @ 2022-06-12 1234/week @ 2022-06-19 1107/week @ 2022-06-26 1401/week @ 2022-07-03 1341/week @ 2022-07-10 2030/week @ 2022-07-17 1340/week @ 2022-07-24 1735/week @ 2022-07-31 2070/week @ 2022-08-07 1744/week @ 2022-08-14 1719/week @ 2022-08-21 2365/week @ 2022-08-28 2077/week @ 2022-09-04 2949/week @ 2022-09-11 1903/week @ 2022-09-18 1526/week @ 2022-09-25

8,657 downloads per month
Used in 37 crates (29 directly)

EPL-2.0 license

33KB
769 lines

Colored JSON output for Rust ci docs.rs Crates.io

Also see:

Screenshot

Using

Add it to your project:

[dependencies]
colored_json = "3"

And then color your JSON output:

extern crate colored_json;

use colored_json::prelude::*;

fn main() -> ::std::result::Result<(), Box<::std::error::Error>> {
    println!(
        "{}",
        r#"
    {
        "array": [
            "ele1",
            "ele2"
        ],
        "float": 3.1415926,
        "integer": 4398798674962568,
        "string": "string"
    }
    "#.to_colored_json_auto()?
    );
    Ok(())
}

Or directly write it out:

extern crate serde_json;
extern crate colored_json;
use serde_json::{from_str, Value};
use std::io::stdout;
use std::io::Write;

pub fn main() -> ::std::result::Result<(), Box<::std::error::Error>> {
    let value: Value = from_str(r#"
        {
            "array": [
                "ele1",
                "ele2"
            ],
            "float": 3.1415926,
            "integer": 4398798674962568,
            "string": "string"
        }
    "#)?;
    let out = stdout();
    {
        let mut out = out.lock();
        colored_json::write_colored_json(&value, &mut out)?;
        out.flush()?;
    }
    Ok(())
}

Dependencies

~465–760KB
~16K SLoC