#json #colored #color #colour #coloured

colored_json

Colorize JSON, for printing it out on the command line

12 releases (2 stable)

✓ Uses Rust 2018 edition

2.0.0 Feb 1, 2019
1.0.0 Dec 5, 2018
0.6.2 Nov 30, 2018
0.5.0 Nov 29, 2018
0.1.0 Nov 28, 2018

#44 in Command-line interface

Download history 15/week @ 2019-01-20 14/week @ 2019-01-27 70/week @ 2019-02-03 24/week @ 2019-02-10 23/week @ 2019-02-17 27/week @ 2019-02-24 27/week @ 2019-03-03 14/week @ 2019-03-10 17/week @ 2019-03-17 61/week @ 2019-03-24 26/week @ 2019-03-31 7/week @ 2019-04-07 6/week @ 2019-04-14 26/week @ 2019-04-21 10/week @ 2019-04-28

140 downloads per month
Used in 2 crates

EPL-2.0 license

32KB
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

~1.5MB
~20K SLoC