pub fn parse_to_serde_value<T: DeserializeOwned>(
text: &str,
parse_options: &ParseOptions,
) -> Result<T, ParseError>Expand description
Parses a string containing JSONC to a serde_json::Value or any
type that implements serde::Deserialize.
Requires the “serde” cargo feature:
jsonc-parser = { version = "...", features = ["serde"] }§Example
Parsing to a serde_json::Value:
use jsonc_parser::parse_to_serde_value;
let json_value: serde_json::Value = parse_to_serde_value(
r#"{ "test": 5 } // test"#,
&Default::default(),
).unwrap();Or to a concrete type:
use jsonc_parser::parse_to_serde_value;
#[derive(serde::Deserialize)]
struct Config {
test: u32,
}
let config: Config = parse_to_serde_value(
r#"{ "test": 5 } // test"#,
&Default::default(),
).unwrap();Empty or whitespace-only input deserializes as null, which means
Option<T> will produce None while other types will return a
type-mismatch error.