Crates.io | pjson |
lib.rs | pjson |
version | 0.2.2 |
source | src |
created_at | 2021-02-22 19:45:55.824779 |
updated_at | 2021-02-25 13:43:50.347104 |
description | JSON stream parser |
homepage | |
repository | https://github.com/tidwall/pjson.rs |
max_upload_size | |
id | 359140 |
size | 15,478,524 |
A JSON stream parser for Rust.
This is a port of the pjson Go library.
It's designed to be very fast and use zero allocations.
Print all string values from a JSON document.
fn main() {
let json = br#"
{
"name": {"first": "Tom", "last": "Anderson"},
"age":37,
"children": ["Sara","Alex","Jack"],
"fav.movie": "Deer Hunter",
"friends": [
{"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
{"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
{"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
]
}
"#;
pjson::parse(json, 0, |start: usize, end: usize, info: usize) i64 {
if info&(pjson::STRING|pjson::VALUE) == pjson::STRING|pjson::VALUE {
let el = String::from_utf8(json[start..end].to_vec()).unwrap();
println!("{}", el);
}
1
});
}
// output:
// "Tom"
// "Anderson"
// "Sara"
// "Alex"
// "Jack"
// "Deer Hunter"
// "Dale"
// "Murphy"
// "ig"
// "fb"
// "tw"
// "Roger"
// "Craig"
// "fb"
// "tw"
// "Jane"
// "Murphy"
// "ig"
// "tw"