Function jsonpath_lib::select[][src]

pub fn select<'a>(
    json: &'a Value,
    path: &str
) -> Result<Vec<&'a Value>, JsonPathError>
Expand description

It is a simple select function. but it compile the jsonpath argument every time.

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

let json_obj = json!({
    "school": {
        "friends": [
            {"name": "친구1", "age": 20},
            {"name": "친구2", "age": 20}
        ]
    },
    "friends": [
        {"name": "친구3", "age": 30},
        {"name": "친구4"}
]});

let json = jsonpath::select(&json_obj, "$..friends[0]").unwrap();

assert_eq!(json, vec![
    &json!({"name": "친구3", "age": 30}),
    &json!({"name": "친구1", "age": 20})
]);