jsonpath

Crates.iojsonpath
lib.rsjsonpath
version0.1.1
sourcesrc
created_at2017-12-28 23:49:38.556464
updated_at2018-04-01 12:06:52.272229
descriptionJSONPath for Rust
homepagehttps://github.com/greyblake/jsonpath-rs
repositoryhttps://github.com/greyblake/jsonpath-rs
max_upload_size
id44766
size30,259
Serhii Potapov (greyblake)

documentation

https://docs.rs/jsonpath

README

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

Commit count: 105

cargo fmt