JSON to Rust
Generate Rust structs with Serde derives, snake_case fields, Option nullability, and rename attributes.
- Runs in your browser
- Free, no signup
use serde::{Deserialize, Serialize};
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Profile {
pub bio: String,
pub reputation: i64,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Root {
pub id: i64,
pub name: String,
pub email: String,
pub is_admin: bool,
pub roles: Vec<String>,
pub profile: Profile,
}
Your files are processed locally in your browser and are not uploaded to our server.
Serde is the de facto standard for serialization in the Rust ecosystem. Manually writing Rust structs with appropriate Serde derive macros and attributes is labor-intensive. This generator automates the entire process.
The tool inspects JSON payloads, converts field names into idiomatic snake_case, attaches #[serde(rename = "...")] attributes where keys differ, wraps nullable fields in Option<T>, and derives Serialize, Deserialize, Clone, Debug, and PartialEq on every generated struct.
How to use this tool
- Paste your JSON payload into the input editor or click "Load Sample".
- Specify your root struct name (e.g. Root, ApiResponse, or Config).
- View generated Rust code with Serde attributes on the right editor.
- Click "Copy Code" or "Download .rs" to integrate directly into your Rust crate.
Comprehensive Serde Attribute Integration
Fields whose original JSON names violate Rust identifiers or use camelCase/kebab-case automatically receive #[serde(rename = "original_name")]. Nullable fields receive Option<T>, preventing deserialization crashes.
Frequently asked questions
Which crates are required to compile the generated Rust code?
You only need the standard serde crate with the "derive" feature enabled: serde = { version = "1.0", features = ["derive"] } in your Cargo.toml.