JSON to Rust Struct Generator
Generate Rust structs with serde Serialize and Deserialize derives from a JSON sample, with snake_case fields, rename attributes and Option for nullable keys.
Free · No sign-up · Your inputs stay in your browser
Input
Generate Rust types from JSON
Output
Rust
704 characters
Derives serde's Serialize and Deserialize. Keys are converted to snake_case with #[serde(rename)] where the JSON name differs, nullable or missing keys become Option<T>, and mixed values fall back to serde_json::Value. Types come from this one sample: give fields that are null here a real value to type them.
Runs in this browser. Nothing you paste is sent to a server.
About this tool
Method, assumptions, practical next steps, and limits.
The types chosen
Whole numbers become i64 and fractions f64; strings are owned String so the struct does not borrow from the input. Values whose type changes between items fall back to serde_json::Value. Narrow integers (u32, u8) by hand where the API documents a range, and add #[serde(rename_all = "camelCase")] if you prefer one attribute on the struct to one per field.
Missing versus null
With #[serde(default)] an absent key deserialises to None instead of failing, and skip_serializing_if = "Option::is_none" leaves it out again when writing. The serde attribute reference lists the rest, including deny_unknown_fields for strict parsing.