2 releases

Uses old Rust 2015

0.1.1 Apr 1, 2018
0.1.0 Dec 28, 2017

#2106 in Parser implementations

Download history 3688/week @ 2024-03-14 4032/week @ 2024-03-21 3313/week @ 2024-03-28 4118/week @ 2024-04-04 3986/week @ 2024-04-11 3293/week @ 2024-04-18 3346/week @ 2024-04-25 4719/week @ 2024-05-02 3651/week @ 2024-05-09 3370/week @ 2024-05-16 3720/week @ 2024-05-23 3379/week @ 2024-05-30 3094/week @ 2024-06-06 4139/week @ 2024-06-13 3463/week @ 2024-06-20 2383/week @ 2024-06-27

13,864 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

~7.5MB
~151K SLoC