Free tool · no sign-up · runs in your browser
JSON to Rust struct.
Paste a JSON response, get serde structs ready to paste into your crate. Every item of an array is merged, not just the first one, so a key that is sometimes missing or null becomes Option up front instead of a deserialize error in production. camelCase keys get renamed, keywords like type are handled, and nested objects get their own structs. Your JSON is never uploaded.
- Merges every array item
- Option for null + missing keys
- rename / rename_all done for you
- One-click copy
Your JSON
Paste an API response or a config file. Parsing runs on this page.
Derives
Options
What the generator does
- Nested objects become their own structs, named from the key in PascalCase (
address→Address,orders→Order). - Arrays of objects are merged. Every item is read, not just the first. A key that some items have and others do not becomes
Option<T>, so a missing field is aNoneinstead of a deserialize error in production. - null becomes Option. A key that is
nullin one place and a string in another becomesOption<String>. A key that is only evernullbecomesOption<serde_json::Value>, because the JSON does not say what it holds. - Numbers: whole numbers become
i64(u64above the i64 range), anything with a decimal point becomesf64, and a key that is 7 in one item and 19.99 in another becomesf64. Mixed types (a string here, a number there) becomeserde_json::Value. - Names: keys become snake_case fields. If every key in a struct is camelCase, you get one
#[serde(rename_all = "camelCase")]instead of a rename on every field; otherwise each changed key gets#[serde(rename = "...")]. Rust keywords liketypebecome raw identifiers (r#type), which serde reads and writes as plaintype. - Unknown fields: serde ignores JSON keys that are not in your struct by default (serde container attributes, checked Oct 23, 2026). Tick deny_unknown_fields to make them an error instead.
FAQ
How do I parse JSON into a struct in Rust?
Add serde (with the derive feature) and serde_json to Cargo.toml, paste your JSON above, copy the structs, then call let data: Root = serde_json::from_str(&text)?;. To read from a reqwest response, use resp.json::<Root>().await? (reqwest's json feature).
How do I handle a field that is sometimes missing?
Make it Option<T>. serde fills a missing Option field with None. This tool does it automatically when a key is missing from some items of an array or is null.
How do I map camelCase JSON keys to snake_case Rust fields?
Put #[serde(rename_all = "camelCase")] on the struct, or #[serde(rename = "userName")] on a single field. The generator picks the shorter of the two for each struct.
What if my JSON has a key named type?
type is a Rust keyword, so the field is written as r#type. serde strips the r# prefix, so it still matches the JSON key type.
Should I use f64 for money?
For display, f64 is fine. For arithmetic on money, parse into an integer number of cents or a decimal crate such as rust_decimal, because binary floats cannot represent most decimal amounts exactly.
Is my JSON sent to a server?
No. Parsing and code generation run in your browser. Nothing you paste leaves the page.
Parsing model output into these structs?
LLMs wrap JSON in prose and code fences, leave trailing commas and cut replies off. Our free LLM JSON repair tool fixes the reply first, so serde_json::from_str gets valid JSON.
Open LLM JSON repair →