Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ctron/colored_json
Generating colored JSON in Rust
https://github.com/ctron/colored_json
ansi-colors cli color json rust
Last synced: 4 days ago
JSON representation
Generating colored JSON in Rust
- Host: GitHub
- URL: https://github.com/ctron/colored_json
- Owner: ctron
- License: epl-2.0
- Created: 2018-11-28T13:26:56.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-04-05T12:09:48.000Z (7 months ago)
- Last Synced: 2024-10-05T23:07:30.844Z (about 1 month ago)
- Topics: ansi-colors, cli, color, json, rust
- Language: Rust
- Homepage: https://crates.io/crates/colored_json
- Size: 210 KB
- Stars: 27
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Colored JSON output for Rust [![ci](https://github.com/ctron/colored_json/actions/workflows/ci.yaml/badge.svg)](https://github.com/ctron/colored_json) [![docs.rs](https://img.shields.io/docsrs/colored_json)](https://docs.rs/colored_json/latest/colored_json/) [![Crates.io](https://img.shields.io/crates/v/colored_json.svg)](https://crates.io/crates/colored_json)
![Screenshot](Screenshot.png)
## Using
Add it to your project:
~~~toml
[dependencies]
colored_json = "4"
~~~And then color your JSON output:
~~~rust
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:
~~~rust
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(())
}
~~~