Skip to content
100% local

JSON to Rust struct

Turn a JSON document into Rust structs ready for serde.

Input
Output

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.

FAQ

Does it install serde or add it to Cargo.toml?
No. It only generates the struct code. Add serde with the derive feature to your Cargo.toml separately: serde = { version = "1", features = ["derive"] }.
What happens to a field that is null in some records and present in others?
When "Wrap null fields in Option<T>" is on, that field becomes Option<T> so it deserializes correctly whether it is present, null or missing.
Why does a field get a #[serde(rename = "...")] attribute?
That appears when camelCase renaming is off and the JSON key does not match the generated snake_case Rust field name, so the exact original key is preserved for deserialization.
Can it generate structs from an array at the top level?
Yes. An array of objects produces a type alias like pub type Root = Vec<Item>; plus the Item struct, merging fields across every element in the array.
Is my JSON uploaded anywhere?
No. Struct generation runs entirely in your browser — your JSON never leaves your device.