JSON to Rust Serde Struct Generator
Generate typed Rust structs with Serde serialization & deserialization attributes from JSON.
- 100% free
- Private in browser
- No signup
- No watermarks
Rust Structs (1)
use serde::{Deserialize, Serialize};
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProjectConfig {
pub project_id: i64,
pub name: String,
pub active: bool,
pub dependencies: Vec<String>,
}About JSON to Rust Serde Struct Generator
The JSON to Rust Struct Converter generates Rust structs with Serde derives from a sample JSON payload. Paste a response, set the root struct name, and the tool writes pub snake_case fields with Serialize, Deserialize, Debug, Clone, Default, and PartialEq derived. Whole numbers become i64, decimals f64, arrays Vec<T>, and each nested object gets its own struct. Every struct also carries rename_all = "camelCase", so remove that line when your JSON keys are snake_case. Types come from one sample only.
How to use JSON to Rust Serde Struct Generator
- Enter a root struct name, such as ProjectConfig.
- Paste your sample JSON into the Input JSON box.
- Review the fields and serde attributes in the Rust Structs panel.
- Click Copy Rust Code and add serde with the derive feature to Cargo.toml.
Key features
- pub structs deriving Default, Debug, Clone, PartialEq, Serialize, and Deserialize
- snake_case field names, with #[serde(rename)] for camelCase keys
- Maps whole numbers to i64, decimals to f64, and booleans to bool
- Creates a separate struct for each nested object
- Types arrays as Vec<T> based on their first element
- Types null values as Option<serde_json::Value>
Frequently asked questions
- How do I convert JSON to a Rust struct?
- Paste your JSON into the Input JSON box, set a root struct name, and the structs are generated instantly. Click Copy Rust Code to copy them into your crate.
- Which crates does the generated code need?
- It needs serde with the derive feature, for example serde = { version = "1", features = ["derive"] }. Add serde_json as well to parse the JSON, and because null values and empty arrays are typed as serde_json::Value.
- Why does deserializing fail on my snake_case keys?
- Because every struct is generated with #[serde(rename_all = "camelCase")]. With that attribute Serde looks for projectId when the field is project_id. If your JSON keys are snake_case, delete the rename_all line and the fields will match.
- Which Rust types are used for JSON numbers?
- Whole numbers become i64 and numbers with a decimal part become f64. Narrow them by hand where you know the range, for example u32 for a count or u64 for an unsigned id.
- How do I handle keys that are sometimes missing?
- Wrap the field type in Option<T> yourself. The generator makes every field required except those that are null in the sample, so a missing key causes a "missing field" error until you change the type.
Related In-Depth Guides
Learn practical workflows, real-world examples, and expert tips in our comprehensive guides:
Password Entropy Explained: How Bits Measure Brute-Force Cracking Time
Understand Shannon entropy in passwords, character pool combinations, and how many seconds, years, or millennia it takes GPUs to crack modern passphrases.
How to Convert Docker Run Commands to Docker Compose YAML Files
A comprehensive developer guide to transforming complex docker run commands into clean, maintainable docker-compose.yml files.
Web Accessibility & Color Contrast (WCAG 2.1): How to Design AA & AAA Palettes
A practical guide to color contrast ratios, accessibility compliance, WCAG 2.1 AA/AAA standards, and building accessible UI palettes.
Rate this tool
Be the first to rate — helps others and improves this page.