Function jsonpath_rust::find_slice

source ·
pub fn find_slice<'a>(
    path: &'a JsonPathInst,
    json: &'a Value,
) -> Vec<JsonPathValue<'a, Value>>
Expand description

finds a slice of data in the set json. The result is a vector of references to the incoming structure.

In case, if there is no match find_slice will return vec![NoValue].

§Example

use jsonpath_rust::{JsonPathInst, JsonPathValue};
use serde_json::json;

let data = json!({"first":{"second":[{"active":1},{"passive":1}]}});
let path = JsonPathInst::from_str("$.first.second[?(@.active)]").unwrap();
let slice_of_data = jsonpath_rust::find_slice(&path, &data);

let expected_value = json!({"active":1});
let expected_path = "$.['first'].['second'][0]".to_string();

assert_eq!(
    slice_of_data,
    vec![JsonPathValue::Slice(&expected_value, expected_path)]
);