JSON to Rust
Paste a JSON payload and get Rust structs deriving Serialize and Deserialize. Fields are renamed to snake_case with a serde rename attribute wherever that differs from the JSON key, optional fields are wrapped in Option and marked skip_serializing_if so an absent field stays absent on the way back out rather than becoming an explicit null the original document never had.
How it works
Paste a representative JSON sample and the Rust declarations appear on the right. The types are inferred from what is actually in the sample, so the more complete your example, the better the result — one array element with an extra field is enough to have that field marked optional rather than missed.
Each object becomes a struct deriving Serialize and Deserialize, with fields renamed to snake_case and a serde rename attribute wherever that differs from the JSON key.
Optional fields are wrapped in Option and marked skip_serializing_if, so a field that was absent in the input stays absent on the way back out rather than being written as an explicit null the original document never had.
Generation runs entirely in your browser — nothing you paste is uploaded.
Frequently asked questions
Why is skip_serializing_if added to optional fields?
Without it, a field that was None serialises as an explicit null. That changes the document: a key that was simply absent in the input reappears as present-but-null on the way out, which some consumers treat differently. skip_serializing_if keeps absent fields absent.
When is a serde rename attribute added?
Only when the snake_case Rust field name differs from the JSON key. A key that is already snake_case needs no attribute, so the struct stays readable rather than carrying a rename on every line.
Could I use serde rename_all instead?
Yes, and for a payload that is consistently camelCase a single #[serde(rename_all = "camelCase")] on the struct is tidier. Per-field renames are generated because they are correct for any mix of key styles, including the ones a container attribute cannot express.
Why are whole numbers i64 and decimals f64?
They are the widest safe defaults for values arriving from JSON, whose numbers are IEEE doubles with no declared width. Narrow them to u32 or i16 where you know the range — the sample cannot tell you that.
What derives are included?
Debug, Clone, Serialize and Deserialize, which covers printing, copying and both directions of serde. Add PartialEq, Default or others as your code needs them.
Related tools
JSON to Go Struct Converter
This JSON to Go converter generates structs with the json tags encoding/json needs.
JSON to Kotlin
Turn a JSON sample into Kotlin data classes annotated for kotlinx.serialization, with a package of your choosing.
JSON to TypeScript Converter
This JSON to TypeScript converter turns a sample payload into exported interfaces.