Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/evanxg852000/erjson

A simple rust json parser
https://github.com/evanxg852000/erjson

json json-parser rust rust-library

Last synced: about 13 hours ago
JSON representation

A simple rust json parser

Awesome Lists containing this project

README

        

## erjson: A simple rust json parser

# Examples

```rust
use erjson::{ JSONDocument, JSONValue };

fn main() {
let data = r#"{
"name": "John Doe",
"age": 43,
"props": { "weight": 76, "height": 2.3 },
"primes": [ 11, 13, 17, 19, 23 ],
"colors": [ "red", "blue" ]
}"#;

let json = String::from(data);
let mut doc = JSONDocument::new();
match doc.parse_string(json) {
Ok(ref mut v) => {
println!("name: {}", v.get("name").unwrap()); // John Doe
println!("age: {}", v.get("age").unwrap()); // 43
match v {
JSONValue::Object(hm) => {
*hm.get_mut("age").unwrap() = JSONValue::Number(45f64);
}
_ => {}
};
println!("age: {}", v.get("age").unwrap()); // 45
},
Err(err) => print!("err: {}", err)
}

}

```