pjson 0.2.2

JSON stream parser
Documentation
  • Coverage
  • 90.91%
    20 out of 22 items documented1 out of 1 items with examples
  • Size
  • Source code size: 15.47 MB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.17 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • tidwall/pjson.rs
    13 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • tidwall

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"