format · validate · convert · runs locally

Parse JSON in Rust

How to parse a JSON string into an object and serialize (stringify) an object back to JSON in Rust. serde_json is the de-facto standard crate for JSON in Rust. Need to clean up the JSON first? Use the formatter & validator.

Parse JSON (string → object)

// serde_json
let obj: serde_json::Value = serde_json::from_str(text)?;

Stringify (object → JSON string)

let text = serde_json::to_string_pretty(&obj)?;

Frequently asked questions

How do I parse JSON in Rust?

serde_json is the de-facto standard crate for JSON in Rust. Parse with the snippet above; the result is a native object/map you can read.

How do I pretty-print JSON in Rust?

Use the stringify snippet above with indentation, or paste your JSON into the formatter on this page.