JSON to Rust Struct Generator
Generate Rust serde structs with rename attributes from JSON samples.
- 100% client-side · your data never leaves your browser
- Instant, no rate limits
- Free, no sign-up
Your result appears here
Paste JSON into the panel on the left — everything runs privately in your browser.
Overview
JSON to Rust Struct Generator — serde Structs Online
Generate Rust structs with serde Serialize/Deserialize derives from any JSON sample. JsonDrift infers field types, converts keys to snake_case, and adds #[serde(rename = "...")] whenever the Rust field name differs from the JSON key — so your structs round-trip cleanly with serde_json. Runs entirely in your browser.
Why generate Rust structs from JSON?
serde needs concrete struct definitions to deserialize JSON into typed Rust values. Copying field names from API docs by hand misses optional fields and gets types wrong. Generating from a real response captures the shape you actually receive, so json_from_str compiles and deserializes on the first try.
What gets generated
Each JSON object becomes a #[derive(Debug, Serialize, Deserialize)] struct. Whole numbers map to i64, decimals to f64, strings to String, booleans to bool, arrays to Vec<T>, and null fields to Option<serde_json::Value>. Keys are converted to idiomatic snake_case, and a #[serde(rename)] attribute preserves the original JSON key.
- String, i64, f64, bool, Vec<T>, Option<T>
- snake_case fields with #[serde(rename = "originalKey")]
- Nested objects become their own structs
- use serde::{Serialize, Deserialize}; header included
Using the structs with serde_json
Add serde and serde_json to Cargo.toml (serde with the derive feature), paste the generated structs into your module, and call serde_json::from_str::<Root>(&body) to deserialize. Because forward references are allowed within a module, the order of the generated structs does not matter.
Review before shipping
Generated structs reflect one sample. Widen numeric types to f64 if a field is sometimes fractional, wrap nullable or sometimes-missing fields in Option, and consider chrono types for timestamps. For fields that are always present but optional in other responses, add #[serde(default)].
FAQ
Frequently asked questions
How do I convert JSON to a Rust struct?
Paste a JSON sample and JsonDrift infers serde structs with the right types and rename attributes, ready to paste into your crate.
Are serde rename attributes included?
Yes. When a snake_case field name differs from the JSON key, a #[serde(rename = "...")] attribute preserves the original key.
What Rust types are used for numbers?
Whole numbers become i64 and decimals become f64. Widen to f64 if a field can be either to avoid deserialization errors.
Is my JSON sent anywhere?
No. Struct generation runs locally in your browser.
Continue with a related tool
All tools- JSON to Go Struct Generator
Infer Go struct definitions with JSON field tags from example JSON.
- JSON to Kotlin Data Class Generator
Generate Kotlin data classes with @SerializedName from JSON samples.
- JSON to Swift Codable Generator
Generate Swift Codable structs with CodingKeys from JSON samples.
- JSON to Zod Schema Generator
Generate Zod schemas and inferred TypeScript types from JSON samples.
- JSON to C# Class Generator
Generate C# classes with JsonProperty attributes from JSON examples.
- JSON to Java Class Generator
Generate Java classes with Jackson annotations from JSON samples.