#json #colored #color #colour #coloured

colored_json

Colorize JSON, for printing it out on the command line

16 releases (6 stable)

3.1.0 Mar 21, 2023
3.0.1 Sep 19, 2022
2.1.0 Nov 4, 2019
2.0.0 Feb 1, 2019
0.6.2 Nov 30, 2018

#22 in Command-line interface

Download history 1732/week @ 2022-12-09 1786/week @ 2022-12-16 1061/week @ 2022-12-23 963/week @ 2022-12-30 1609/week @ 2023-01-06 1285/week @ 2023-01-13 1859/week @ 2023-01-20 1795/week @ 2023-01-27 1707/week @ 2023-02-03 1583/week @ 2023-02-10 2067/week @ 2023-02-17 2479/week @ 2023-02-24 2474/week @ 2023-03-03 2731/week @ 2023-03-10 2488/week @ 2023-03-17 2382/week @ 2023-03-24

10,452 downloads per month
Used in 58 crates (37 directly)

EPL-2.0 license

33KB
769 lines

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

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

~0.6–5.5MB
~93K SLoC