expression
Pretty-printed JSON
Indent JSON for human review. Whitespace outside strings does not change its data model. Serde and serde_json are external crates; use the staged Cargo manifest. Expected stdout (not executed): true 2 Common mistake: Using whitespace-sensitive string comparison to test semantic JSON equality.
Formal Syntax & Structure
rust syntaxrust
serde_json::to_string_pretty(&value) -> Result<String, Error>Working Example
Example Snippetrust
fn main() { let text = serde_json::to_string_pretty(&[3, 5]).unwrap(); let decoded: Vec<u32> = serde_json::from_str(&text).unwrap(); println!("{} {}", text.contains('\n'), decoded.len());}