[][src]Function jsonpath_lib::select_as_str

pub fn select_as_str(json: &str, path: &str) -> Result<String, String>

This function compile a jsonpath everytime and it convert &str to jsonpath's RefValue everytime and then it return a json string.

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

let ret = jsonpath::select_as_str(r#"
{
    "school": {
        "friends": [
                {"name": "친구1", "age": 20},
                {"name": "친구2", "age": 20}
            ]
    },
    "friends": [
        {"name": "친구3", "age": 30},
        {"name": "친구4"}
    ]
}
"#, "$..friends[0]").unwrap();

assert_eq!(ret, r#"[{"name":"친구3","age":30},{"name":"친구1","age":20}]"#);