Skip to main content

from_value

Function from_value 

Source
pub fn from_value<T>(value: JsonValue) -> Result<T, DeserializeError>
Expand description

Deserializes the JSON value into an instance of type T.

ยงExample

use serde::Deserialize;
use json_syntax::{json, JsonValue};

#[derive(Deserialize, Debug)]
struct User {
    fingerprint: String,
    location: String,
}

let j: JsonValue = json!({
  "fingerprint": "0xF9BA143B95FF6D82",
  "location": "Menlo Park, CA"
});

let u: User = json_syntax::from_value(j).unwrap();
println!("{:#?}", u);