Crates.io | jsonpath_rs |
lib.rs | jsonpath_rs |
version | 0.0.3 |
source | src |
created_at | 2022-04-06 13:46:28.389465 |
updated_at | 2022-04-10 13:26:12.952437 |
description | A JsonPath engine written in Rust |
homepage | |
repository | https://github.com/RedisJSON/jsonpath_rs |
max_upload_size | |
id | 563151 |
size | 145,282 |
A JSONPath 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.
Add the following to your cargo.toml
[dependencies]
jsonpath_rs = { git = "https://github.com/RedisJSON/jsonpath_rs.git", branch = "master" }
Usage example:
extern crate jsonpath_rs
#[macro_use] extern crate serde_json;
fn main() {
let mut query = jsonpath_rs::compile("$..friends[0]");
let path = jsonpath_rs::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 = path.calc(&json_obj);
assert_eq!(json, vec![
&json!({"name": "foo3", "age": 30}),
&json!({"name": "foo1", "age": 20})
]);
}
jsonpath_rs
pass Almost all the tests on https://github.com/freestrings/jsonpath, to run the tests:
cargo test