arson
arson is a simple rust json library for parsing string. it has nice formatted colored output
Cargo.toml
[dependencies]
arson = "x.x"
Example
use arson::{JSONError, Parser, JSON, JSON::*};
fn main() -> Result<(), JSONError> {
let json_str = std::fs::read_to_string("ex.json").unwrap();
let json_str = r#"{
"name": "John Doe",
"age": 43,
"address": {
"street": "10 Downing Street",
"city": "London"
},
"phones": [
"+44 1234567",
"+44 2345678"
]
} "#;
let json = json_str.parse::<JSON>().expect("Failed to parse json");
let json = Parser::parse(json_str.chars())?;
println!("{:?}", json);
match json {
Array(val) => {} Object(val) => {} String(val) => {} Number(val) => {} Bool(val) => {} Null => {}
}
Ok(())
}
Output
{
"address": {
"city": "London",
"street": "10 Downing Street",
},
"name": "John Doe",
"age": 43,
"phones": [
+44 1234567,
+44 2345678,
],
}