pub fn compile<'a>(
path: &'a str
) -> impl FnMut(Value) -> Result<Value, String> + 'a
extern crate jsonpath_lib as jsonpath;
#[macro_use] extern crate serde_json;
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);