Crates.io | colored_json |
lib.rs | colored_json |
version | 5.0.0 |
source | src |
created_at | 2018-11-28 13:46:30.196589 |
updated_at | 2024-04-05 12:09:13.712888 |
description | Colorize JSON, for printing it out on the command line |
homepage | https://github.com/ctron/colored_json |
repository | https://github.com/ctron/colored_json |
max_upload_size | |
id | 99071 |
size | 51,230 |
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(())
}