Paste an API response and get serde structs ready for serde_json::from_str
Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.Decoding an API response with serde_json needs a struct for every object, with snake_case fields, a rename for each key spelled another way, and Option wherever a value can be null or missing. Paste the response and get those structs with Serialize and Deserialize derived, a single rename_all when the keys are camelCase, and i64 or f64 chosen per field.
Paste or type your input.
Choose the options you need.
Press Ctrl+Enter, then copy or download.
Rust decodes JSON with serde, and every object needs a struct whose fields have the right types and whose names map back to the JSON keys. This converter writes those structs from a sample, so a long API response becomes compiling Rust in one paste.
| JSON value | Rust type |
|---|---|
| "text" | String |
| true / false | bool |
| 42 (whole numbers only) | i64 |
| 4.5 (any decimal seen) | f64 |
| null, and also a type | Option |
| only null, or mixed kinds | serde_json::Value |
| [ ... ] | Vec<...> |
| { } empty | Map<String, Value> |
| { ... } | a struct of its own |
Missing keys. All the objects of an array are merged into one struct. A key that some of them leave out becomes an Option, because serde treats a missing Option as None and every other missing field as an error. Those fields also get skip_serializing_if, so writing the struct back out leaves them out again.
The rest of the article, and all 6 questions about JSON to Rust Struct Converter, are on the JSON to Rust Struct Converter page.
Paste a JSON sample into the converter and the Rust structs appear beside it, each deriving Serialize and Deserialize. Add serde with the derive feature and serde_json to Cargo.toml, paste the structs into a module, and decode with serde_json::from_str::<Root>(&text).
A field becomes Option when the sample shows it as null, or when some objects of an array leave the key out. Serde decodes a missing key into an Option as None, while any other missing field is an error, so Option is what lets the struct accept every object in the sample.
Fields are written in snake_case, as Rust style asks. When every key is the camelCase form of its field, the struct gets one #[serde(rename_all = "camelCase")]; otherwise each field spelled differently gets its own #[serde(rename = "key")], so keys like first-name or 2fa still decode.
JSON does not say how large a number may get, so i64 is the safe whole-number type and f64 matches the double precision JSON numbers are read with. A field becomes f64 as soon as any sample value has a decimal part, because serde refuses to read 4.5 into an integer.
Rates and rules change; check the source before you rely on a figure.
Still stuck? Ask about JSON to Rust Struct Converter and anybody who knows can answer. No account needed.
Same job, other tools: TSV to JSON – Convert tab-separated values, such as a paste from Excel, into JSON · JSON to YAML – Turn JSON into clean, readable YAML for configs · Query String Parser – Split a URL query string into a table of decoded parameters.