#json #colored #coloured #color #colour

colored_json

Colorize JSON, for printing it out on the command line

19 releases (9 stable)

4.1.0 Nov 15, 2023
3.3.0 Oct 12, 2023
3.2.0 May 22, 2023
3.1.0 Mar 21, 2023
0.6.2 Nov 30, 2018

#34 in Command-line interface

Download history 3513/week @ 2023-11-01 5293/week @ 2023-11-08 4151/week @ 2023-11-15 3973/week @ 2023-11-22 4070/week @ 2023-11-29 3541/week @ 2023-12-06 3274/week @ 2023-12-13 2218/week @ 2023-12-20 1963/week @ 2023-12-27 3537/week @ 2024-01-03 3883/week @ 2024-01-10 4019/week @ 2024-01-17 3708/week @ 2024-01-24 4169/week @ 2024-01-31 3440/week @ 2024-02-07 3247/week @ 2024-02-14

15,379 downloads per month
Used in 73 crates (52 directly)

EPL-2.0 license

27KB
519 lines

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

Screenshot

Using

Add it to your project:

[dependencies]
colored_json = "4"

And then color your JSON output:

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:

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.4–0.9MB
~18K SLoC