[][src]Function jsonpath_lib::select_as

pub fn select_as<T: DeserializeOwned>(
    json: &str,
    path: &str
) -> Result<T, String>

This function compile a jsonpath everytime and it convert &str to jsonpath's RefValue everytime and then it return a deserialized-instance of type T.

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

use serde::{Deserialize, Serialize};

#[derive(Deserialize, PartialEq, Debug)]
struct Person {
    name: String,
    age: u8,
    phones: Vec<String>,
}

let ret: Person = jsonpath::select_as(r#"
{
    "person":
        {
            "name": "Doe John",
            "age": 44,
            "phones": [
                "+44 1234567",
                "+44 2345678"
            ]
        }
}
"#, "$.person").unwrap();

let person = Person {
    name: "Doe John".to_string(),
    age: 44,
    phones: vec!["+44 1234567".to_string(), "+44 2345678".to_string()],
};

assert_eq!(person, ret);