[][src]Function jsonpath_lib::selector

pub fn selector(json: &Value) -> impl FnMut(&str) -> Result<Value, String>

Read the same Json multiple times using different JsonPath

extern crate jsonpath_lib as jsonpath;
#[macro_use] extern crate serde_json;

let json_obj = json!({
"school": {
   "friends": [{"id": 0}, {"id": 1}]
},
"friends": [{"id": 0},{"id": 1}]
});

let mut selector = jsonpath::selector(&json_obj);

let json = selector("$..friends[0]").unwrap();
let ret = json!([ {"id": 0}, {"id": 0} ]);
assert_eq!(json, ret);

let json = selector("$..friends[1]").unwrap();
let ret = json!([ {"id": 1}, {"id": 1} ]);
assert_eq!(json, ret);