JSON to Rust Converter
Generate serde structs from a JSON sample.
JSON
Rust
About the JSON to Rust converter
Rust needs a concrete type before it will deserialise anything, so working with a new API always begins with writing structs. This does that step for you.
Output includes the serde derives and the rename attributes needed where JSON keys are not snake_case.
Renames are added where they are needed
Rust fields are snake_case; JSON keys frequently are not. Where they differ, a `#[serde(rename = "...")]` attribute is emitted so deserialisation matches the original key exactly.
Where the key is already snake_case no attribute is added, keeping the output clean.
Types chosen
Whole numbers become `i64` and fractional ones `f64` — deliberately wide, since narrowing later is safe and overflowing is not. A null-only field becomes `serde_json::Value`, which accepts anything.
Consider adding `#[serde(default)]` to fields that may be absent; one sample cannot tell which those are.
Types come from one sample
Everything here is inferred from the JSON you paste. A field that happens to be absent from your example will be absent from the output, and a field that is null in the sample cannot be typed at all — only marked as nullable.
Paste the richest response you have, then review the optional and nullable fields by hand. Treat the result as a fast first draft rather than a schema.
Frequently asked questions
Do I need serde_json as a dependency?
Only if the output mentions serde_json::Value, which happens for fields that were null or empty in your sample. Otherwise serde with the derive feature is enough.
Why is my null field typed so loosely?
Because a single null tells you nothing about what the field looks like when it is populated. It is marked nullable or optional so the code compiles, and it is the first thing worth correcting by hand.
Is my JSON uploaded?
No. The conversion runs in your browser, which matters when the sample you are pasting is a real API response with real customer data in it.