JSON to Rust

Generate Rust struct definitions with serde derives from JSON.

Paste a JSON sample and get Rust structs with #[derive(Serialize, Deserialize)] ready to drop into a serde_json project. Nested objects become their own structs; arrays become Vec; field names that aren't valid Rust identifiers get a #[serde(rename)] attribute.

Common use cases: writing a typed client for a JSON API, modelling configuration files in Rust, generating fixtures for tests, and getting a starting point that's faster than writing structs by hand for a deeply nested response.

JSON

Rust

Frequently asked questions

Does the output include serde annotations?
Yes — each struct is prefixed with #[derive(Serialize, Deserialize)] so the type can round-trip with serde_json. Field names that aren't valid Rust identifiers get a #[serde(rename = "…")] attribute mapping back to the JSON name.
How are numbers typed?
Integers without a fractional part become i64 (or u64 if always positive); numbers with a decimal point become f64. For very large IDs you may want to swap i64 for String manually to avoid precision loss across systems.
What about optional fields?
A single sample doesn't reveal optionality — every field is generated as required. To mark a field optional, wrap its type in Option<…> and add #[serde(default, skip_serializing_if = "Option::is_none")].
How are nested objects and arrays modelled?
Each nested object becomes its own named struct; arrays become Vec<T>. Heterogeneous arrays (mixed types) fall back to serde_json::Value — refine those manually if you know the variants.