2 releases

Uses old Rust 2015

0.1.1 Apr 1, 2018
0.1.0 Dec 28, 2017

#2684 in Parser implementations

Download history 3157/week @ 2024-07-21 3631/week @ 2024-07-28 3348/week @ 2024-08-04 2507/week @ 2024-08-11 3717/week @ 2024-08-18 2770/week @ 2024-08-25 3224/week @ 2024-09-01 3214/week @ 2024-09-08 3451/week @ 2024-09-15 2962/week @ 2024-09-22 3182/week @ 2024-09-29 1938/week @ 2024-10-06 2765/week @ 2024-10-13 4209/week @ 2024-10-20 3347/week @ 2024-10-27 4269/week @ 2024-11-03

14,680 downloads per month
Used in 7 crates

MIT license

31KB
776 lines

JSONPath for Rust

The library is in hard development stage.

Example

extern crate jsonpath;
extern crate serde_json;

use jsonpath::Selector;
use serde_json::Value;

fn main() {
    let jsondoc = r#"
        {
             "books": [
                 {
                     "title": "Der schwarze Obelist",
                     "author": "Erich Maria Remarque"
                 },
                 {
                     "title": "Le mur",
                     "author": "Jean-Paul Sartre"
                 }
             ]
        }
    "#;

    // Parse JSON document
    let json: Value = serde_json::from_str(jsondoc).unwrap();

    // Create a JSONPath selector
    let selector = Selector::new("$.books.*.title").unwrap();

    // Apply the selector to the JSON and convert Vec<&Value> into Vec<&str>
    let titles: Vec<&str> = selector.find(&json)
        .map(|t| t.as_str().unwrap())
        .collect();

    assert_eq!(titles, vec!["Der schwarze Obelist", "Le mur"]);
}

Roadmap

  • Operators:
    • $ - root element
    • .<name> - named child element
    • * - wildcard (any child item)
    • [<number>] - indexed element in array
    • [<start>:<end>] - slice
    • [:<end>] - slice (to)
    • [<start>:] - slice (from)
  • Handy test helpers
  • Good integration test coverage
  • Benchmarks
  • Refactor
  • Improve error messages
  • Review unwraps
  • Review the public API (rename Selector -> Path ?)
  • Publish a new version
  • Mutable iterator
  • Support filters
    • [?(<expression>)] - Filter expression. Expression must evaluate to a boolean value.
    • @ - current element
    • operator ==
    • operator !=
    • operator >
    • operator <

License

MIT © Sergey Potapov

Contributors

Dependencies

~6–11MB
~147K SLoC