license GitHub issues Rust crates.io

JsonPathCalculator

Json path calculator library for rust. The idea behind this library is that it can operate on any json representation as long as it implements the SelectValue triat. The library has an implementation for serde_json value and ivalue.

Getting Started

Add the following to your cargo.toml

rust [dependencies] jsonpath_rs = { git = "https://github.com/RedisJSON/JsonPathCalculator.git", branch = "master" }

Usage example:

```rust extern crate jsonpath_rs

[macrouse] extern crate serdejson;

fn main() { let mut query = jsonpathrs::compile("$..friends[0]"); let calculator = jsonpathrs::create(&query)

let json_obj = json!({
    "school": {
        "friends": [
            {"name": "foo1", "age": 20},
            {"name": "foo2", "age": 20}
        ]
    },
    "friends": [
        {"name": "foo3", "age": 30},
        {"name": "foo4"}
    ]
});

let json = calculator.calc(&json_obj);

assert_eq!(json, vec![
    &json!({"name": "foo3", "age": 30}),
    &json!({"name": "foo1", "age": 20})
]);

} ```

Tests

jsonpath_rs pass Almost all the tests on https://github.com/freestrings/jsonpath, to run the tests:

rust cargo test