Function jsonpath_rust::find
source · pub fn find(path: &JsonPathInst, json: &Value) -> Value
Expand description
finds a slice of data and wrap it with Value::Array by cloning the data. Returns either an array of elements or Json::Null if the match is incorrect.
In case, if there is no match find
will return json!(null)
.
§Example
use jsonpath_rust::{JsonPathInst, JsonPathValue};
use serde_json::{Value, json};
let data = json!({"first":{"second":[{"active":1},{"passive":1}]}});
let path = JsonPathInst::from_str("$.first.second[?(@.active)]").unwrap();
let cloned_data = jsonpath_rust::find(&path, &data);
assert_eq!(cloned_data, Value::Array(vec![json!({"active":1})]));