expression
serde_json::from_str: parse JSON text
Parse an entire JSON document into a requested type, including primitive and collection types. Extra non-whitespace content is rejected. Serde and serde_json are external crates; use the staged Cargo manifest. Expected stdout (not executed): 12 true Common mistake: Treating multiple adjacent documents as one JSON value.
Formal Syntax & Structure
rust syntaxrust
serde_json::from_str::<T>(text) -> Result<T, Error>Working Example
Example Snippetrust
fn main() { let values: Vec<u32> = serde_json::from_str("[2,4,6]").unwrap(); println!("{}", values.iter().sum::<u32>()); println!("{}", serde_json::from_str::<u32>("2 4").is_err());}