[][src]Function jsonpath_lib::compile

pub fn compile<'a>(
    path: &'a str
) -> impl FnMut(Value) -> Result<Value, String> + 'a

Read multiple Json multiple times with the same JsonPath

let mut template = jsonpath::compile("$..friends[0]");


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

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


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

let json = template(json_obj).unwrap();
let ret = json!([ {"id": 0}, {"name": "Millicent Norman"} ]);
assert_eq!(json, ret);