Turn a JSON sample into Rust structs with serde derives, renames, Option and Vec
Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.Paste a JSON sample and get Rust structs with serde's Serialize and Deserialize derives. Whole numbers become i64 and any decimal makes a field f64; a value that is null or missing from some objects becomes Option<T>, and keys spelt differently from their snake_case field get a serde rename, 1 rename_all when all are camelCase.
Paste a JSON sample, such as an API response, into the left box.
The Rust structs appear as you type, each with #[derive(Serialize, Deserialize)], snake_case fields and the serde renames they need.
Turn on Option for every field or PartialEq if you want them, and set the root struct name.
Press Copy, or Download to save models.rs, and add serde (with the derive feature) and serde_json to Cargo.toml.
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.
How types are chosen.
| 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.
Names. Fields are snake_case. When every key is simply the camelCase form of its field, the struct carries one rename_all; otherwise each differing field gets its own rename. Keywords become raw identifiers such as r#type; self, super and crate cannot be raw, so they become self_ with a rename.
Options. Option on every field suits APIs that may drop any key. Derive PartialEq lets tests compare values. The root struct is called Root unless you name it.
Every output was checked by reading the Rust back with serde's rules and decoding 9 samples with it. Nothing you paste leaves the browser.
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.
Keywords are written as raw identifiers, such as r#type, and serde removes the r# when it matches the key, so no rename is needed. The four keywords that cannot be raw, self, Self, super and crate, become self_ and similar, with a rename back to the original key.
No. The conversion runs in your browser with no request to any server, and the JSON is not stored, so API responses holding tokens or personal data stay on your device. Close the tab and nothing remains.
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.