JSON to Rust Struct Converter
Paste JSON, get idiomatic Rust serde structs instantly, 100% in your browser. Correct i64/u64/f64 typing, Option for nulls, #[serde(rename)] for camelCase. Free.
Options
What is JSON to Rust conversion?
JSON to Rust conversion turns a JSON sample into ready-to-compile Rust structs with serde's #[derive(Serialize, Deserialize)] macros, so you never hand-write deserialization boilerplate for API responses or config files. This fast Rust struct generator infers correct number types, marks absent fields as Option, and adds #[serde(rename)] for non-snake_case keys — all 100% in your browser.
Examples
API response
{"id":101,"name":"Ada Lovelace","email":"ada@example.com","active":true,"roles":["admin","user"]} use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
pub id: i64,
pub name: String,
pub email: String,
pub active: bool,
pub roles: Vec<String>,
}
A typical REST payload becomes a serde-ready struct you can drop into your client. Numbers infer i64, arrays become Vec<String>.
Nested object
{"repo":"serde","owner":{"login":"dtolnay","id":100}} use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
pub repo: String,
pub owner: Owner,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Owner {
pub login: String,
pub id: i64,
}
Nested objects become separate, named structs (Owner) referenced by field — identical shapes are deduplicated.
Array of objects (optional field)
{"users":[{"id":1,"nick":"x"},{"id":2}]} use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
pub users: Vec<User>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User {
pub id: i64,
pub nick: Option<String>,
}
Arrays of objects merge into one element struct. Keys missing from some items become Option<String> — no #[serde(default)] needed.
camelCase keys
{"login":"octocat","publicRepos":15,"followerCount":9001,"createdAt":"2011-01-25"} use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
pub login: String,
#[serde(rename = "publicRepos")]
pub public_repos: i64,
#[serde(rename = "followerCount")]
pub follower_count: i64,
#[serde(rename = "createdAt")]
pub created_at: String,
}
Fields become snake_case with #[serde(rename)] mapping back to the original JSON key. Already-snake keys like login get no rename.
How to convert JSON to Rust
- 1
Paste your JSON
Drop a JSON object, array, or API response into the input box. Conversion starts instantly.
- 2
Tune the output
Rename the root struct and toggle serde derives, Debug and Clone, or pub visibility to match your crate's style.
- 3
Copy or download
Grab the generated Rust with one click and paste it straight into your project.
Common Use Cases
- Typed API clients
- Turn a sample REST or GraphQL response into serde structs for a reqwest or similar client without writing deserialization boilerplate by hand.
- Config and fixture parsing
- Generate structs for JSON config files, test fixtures, or webhook payloads you need to deserialize with serde_json.
- Fast prototyping
- Paste an unfamiliar payload to instantly see its shape as Rust types — a quick way to explore a new API before wiring it up.
How the conversion works
- Structural inference
- Each object becomes a named struct; identical shapes are deduplicated so you get one struct, not copies. Arrays of objects are merged key-by-key, and keys absent from some items become Option<T>.
- Correct number typing
- Integers map to i64, promote to u64 past i64::MAX, and fall back to f64 beyond u64. Floats are detected from the token (1.0, 2e3) so serde deserialization never fails on a float-into-integer mismatch.
- Idiomatic, compilable identifiers
- Keys become snake_case fields with #[serde(rename)] back to the original key; Rust keywords, duplicate names, and non-identifier keys are sanitized so the output always compiles.
- 100% client-side
- Parsing and generation run in your browser with no network calls, so your data stays private.
Tips for clean Rust structs
- Name your root struct
- Set a meaningful root name (e.g. User, ApiResponse) instead of the default Root for readable code.
- Add serde_json only when needed
- serde_json::Value appears for empty or mixed-type arrays and null-only fields. Give those fields a concrete type from a richer sample if you can, or add serde_json to Cargo.toml.
- Review Option vs required
- Fields are marked Option<T> only when a sample omits them. Paste a representative payload so the tool infers required and optional fields accurately.
Frequently asked questions
How do I convert JSON to a Rust struct?
Does it generate serde derives? Do I need serde and serde_json?
How do I use the generated struct to parse JSON?
How are optional and null fields handled?
How does it handle camelCase keys and Rust keywords?
Can it use #[serde(rename_all)] instead of per-field renames?
What Rust number type does it use?
How are dates and timestamps typed?
How do I handle objects with dynamic or unknown keys?
Is my JSON data private and safe?
Can I generate plain Rust structs without serde?
Is the tool free? Do I need an account?
Related Tools
View all tools →Base64 Decoder & Encoder
Encoding & Formatting
Decode and encode Base64 online for free. Real-time conversion with full UTF-8 and emoji support. 100% private — runs in your browser. No signup needed.
Base64 to Image Converter
Encoding & Formatting
Decode a Base64 string or data URI back into an image in your browser. Preview, read dimensions & MIME, then download as PNG, JPG, GIF, SVG. No upload.
CSV to JSON Converter
Encoding & Formatting
Convert CSV to JSON in your browser. RFC 4180, type inference, header row, big-int safe. 100% private, no upload.
.env to JSON Converter
Encoding & Formatting
Paste a .env file, get JSON instantly. Your database passwords, API keys and tokens never leave your browser — 100% private, no upload, free dotenv parser.
Free HTML Entity Decoder — Unescape HTML
Encoding & Formatting
Decode HTML entities and unescape HTML online — free, no signup, 100% in your browser. Converts named, decimal & hex references back to characters; never uploaded.
Free HTML Entity Encoder — Escape HTML
Encoding & Formatting
Encode HTML entities and escape special characters (< > & " ') online — free, no signup, 100% in your browser. Named, decimal, or hex output; never uploaded.