#json #colored #coloured

colored_json

Colorize JSON, for printing it out on the command line

20 releases (10 stable)

5.0.0 Apr 5, 2024
4.1.0 Nov 15, 2023
3.3.0 Oct 12, 2023
3.2.0 May 22, 2023
0.6.2 Nov 30, 2018

#59 in Command-line interface

Download history 4469/week @ 2024-12-08 3804/week @ 2024-12-15 2165/week @ 2024-12-22 2157/week @ 2024-12-29 3697/week @ 2025-01-05 4162/week @ 2025-01-12 3811/week @ 2025-01-19 5646/week @ 2025-01-26 6502/week @ 2025-02-02 3901/week @ 2025-02-09 3541/week @ 2025-02-16 4329/week @ 2025-02-23 4466/week @ 2025-03-02 4348/week @ 2025-03-09 5050/week @ 2025-03-16 3483/week @ 2025-03-23

17,757 downloads per month
Used in 88 crates (65 directly)

EPL-2.0 license

27KB
517 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.5–1MB
~21K SLoC