JSON to Rust struct
Turn a JSON document into Rust structs ready for serde.
JSON to Rust struct
Paste a JSON object or array and this tool generates matching Rust structs, ready to drop into a project that uses serde for serialization. It saves the tedium of hand-writing field types and derive attributes every time an API response or config file changes shape.
The options control how the generated code looks. Choose which traits to derive — Debug, Clone, Serialize, Deserialize, PartialEq — and whether to add #[serde(rename_all = "camelCase")] so idiomatic snake_case Rust fields still deserialize camelCase JSON keys correctly. Null values can become Option<T> automatically, and you can pick i32, i64 or u64 for whole numbers and String or a borrowed &str (with a lifetime) for text. Nested objects can generate as separate top-level structs or be wrapped in their own pub mod, and fields can be public or private.
Arrays of objects are merged into a single struct: a field only present on some items becomes Option<T> automatically, so a struct generated from a handful of sample records still matches the full dataset. Field names are converted to snake_case, Rust keywords are turned into raw identifiers like r#type, and a name that cannot be represented cleanly keeps its original key via #[serde(rename = "...")] instead.
Everything runs locally in your browser — your JSON is never uploaded anywhere, so it is safe to paste real API payloads or config data. Copy the generated code, download it as a .txt file, or send the output back into the input to refine it further.