โ WARNING: This library should not be used in production, it is purely for learning rust and how its library system works.
This is a simple JSON parser written in Rust with full support for JSON5 serialization and deserialization.
The following code snippet shows an example of how to use the parser:
use qjson::{parse_file, parse_str};
fn main() {
let json = r#"{
name: "John Doe",
'age': 42,
"married": true,
"children": ['Jane', "Jack"],
"address": {
"street": "Main St.",
"city": "New York",
"state": "NY"
}
}"#;
let parsed = parse_str(json).unwrap();
println!("{:?}", parsed);
}
The output is the parsed JSON object:
{
"name": "John Doe",
"age": 42,
"married": true,
"children": [
"Jane",
"Jack"
],
"address": {
"street": "Main St.",
"city": "New York",
"state": "NY"
}
}
The following features are provided by the library.
JSON values and numerical values are defined as following:
#[derive(Debug, PartialEq, Clone)]
pub enum JsonNumber {
Int(i64),
Float(f64),
}
#[derive(Debug, PartialEq, Clone)]
pub enum JsonValue {
Null,
Bool(bool),
Number(JsonNumber),
String(String),
Array(Vec<Box<JsonValue>>),
Object(HashMap<String, Box<JsonValue>>),
}
It is also possible to parse single JSON values:
use qjson::{parse_str};
fn main() {
let json = r#"[1, 2, 3]"#;
let parsed = parse_str(json).unwrap();
println!("{:?}", parsed);
}
The output is the parsed JSON array:
[ 1, 2, 3 ]