from_str

Function from_str 

Source
pub fn from_str<'de, T>(s: &'de str) -> Result<T, SerdeJSON5Error>
where T: Deserialize<'de>,
Expand description

Deserialize str to your values/structs/etc. compatible with the serde data model

§Examples

use json_five::from_str;
use serde::Deserialize;
#[derive(Debug, PartialEq, Deserialize)]
struct MyData {
    name: String,
    count: i64,
    maybe: Option<f64>,
}

fn main() {
    let source = r#"
    // A possible JSON5 input
    {
      name: 'Hello',
      count: 42,
      maybe: null
    }
"#;

    let parsed = from_str::<MyData>(source).unwrap();
    let expected = MyData {name: "Hello".to_string(), count: 42, maybe: None};
    assert_eq!(parsed, expected);
}

For convenience in dealing with arbitrary valid JSON5 documents, you may use serde_json’s Value enum. with this crate. This may be something implemented or vendored into json-five in the future.