5 releases

0.2.2 Feb 25, 2021
0.2.1 Feb 25, 2021
0.1.2 Feb 22, 2021
0.1.1 Feb 22, 2021
0.1.0 Feb 22, 2021

#2433 in Parser implementations

Download history 175/week @ 2024-07-20 179/week @ 2024-07-27 154/week @ 2024-08-03 160/week @ 2024-08-10 123/week @ 2024-08-17 136/week @ 2024-08-24 126/week @ 2024-08-31 97/week @ 2024-09-07 62/week @ 2024-09-14 41/week @ 2024-09-21 70/week @ 2024-09-28 67/week @ 2024-10-05 78/week @ 2024-10-12 69/week @ 2024-10-19 50/week @ 2024-10-26 14/week @ 2024-11-02

217 downloads per month

MIT license

3MB
1.5K SLoC

pjson.rs

license crates.io version documentation

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.

Example

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"

No runtime deps