#json #colored #color #colour #coloured

colored_json

Colorize JSON, for printing it out on the command line

13 releases (3 stable)

2.1.0 Nov 4, 2019
2.0.0 Feb 1, 2019
1.0.0 Dec 5, 2018
0.6.2 Nov 30, 2018

#58 in Command-line interface

Download history 193/week @ 2021-02-21 282/week @ 2021-02-28 426/week @ 2021-03-07 202/week @ 2021-03-14 399/week @ 2021-03-21 302/week @ 2021-03-28 541/week @ 2021-04-04 359/week @ 2021-04-11 645/week @ 2021-04-18 510/week @ 2021-04-25 563/week @ 2021-05-02 511/week @ 2021-05-09 496/week @ 2021-05-16 730/week @ 2021-05-23 547/week @ 2021-05-30 379/week @ 2021-06-06

1,752 downloads per month
Used in 15 crates (13 directly)

EPL-2.0 license

31KB
771 lines

Screenshot

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.5–0.8MB
~17K SLoC