JSON to Rust
Paste JSON — get Rust structs with Serde as you type. Nothing leaves your browser.
› More options & type detection
JSON to Rust example
Turn JSON into Rust structs you can parse with serde_json. Each object becomes a pub struct deriving Serialize and Deserialize, field names are converted to snake_case, and a serde rename attribute keeps them matched to the original camelCase keys.
{
"name": "api-gateway",
"version": "1.4.2",
"port": 8080,
"debug": false,
"features": [
"auth",
"rate-limit"
],
"database": {
"url": "postgres://localhost/app",
"poolSize": 10
},
"retryAfterMs": null
}// Example code that deserializes and serializes the model.
// extern crate serde;
// #[macro_use]
// extern crate serde_derive;
// extern crate serde_json;
//
// use generated_module::Config;
//
// fn main() {
// let json = r#"{"answer": 42}"#;
// let model: Config = serde_json::from_str(&json).unwrap();
// }
use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Config {
pub name: String,
pub version: String,
pub port: i64,
pub debug: bool,
pub features: Vec<String>,
pub database: Database,
pub retry_after_ms: Option<serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Database {
pub url: String,
pub pool_size: i64,
}
- Serde derives and renames
- Structs derive Debug, Clone, Serialize and Deserialize. #[serde(rename_all = "camelCase")] is added only where a key needs it, so pool_size reads poolSize from the JSON.
- Option and Vec
- Fields missing from some samples become Option<T>, arrays become Vec<T>. retryAfterMs is null in every sample, so it becomes Option<serde_json::Value> — paste a sample with a value to get a concrete type.
- Integer types
- Whole numbers are i64 by default. “Integer type inference” can force i32 or i64 everywhere instead.
- Strings stay strings
- Dates and UUIDs stay String, since the output depends only on serde and serde_json. Field visibility (pub, pub(crate) or private), a PartialEq derive and skipping empty Option fields when serializing are options.
Convert JSON to any language
The same smart type inference, 28 output formats.
Types that match your real data
Built on the open-source quicktype engine, with quieter defaults and a friendlier editor.
- Optional fields detected
- Fields that are missing or null in some items become optional automatically.
- Merge many samples
- Paste JSON Lines or an array — every example contributes to one accurate type.
- Paste anything
- JavaScript objects, trailing commas, single quotes and comments are repaired for you.
- Sensible defaults
- No surprise enums or date classes — turn detection on only when you want it.
- Every option, every language
- All of Rust’s generator settings, from naming style to framework annotations.
- Private & instant
- Runs in a background thread in your browser. Share links keep data in the URL only.
Frequently asked questions
How do I convert JSON to a Rust struct?+
Paste your JSON, copy the structs into a module, and add serde (with the derive feature) and serde_json to Cargo.toml. Then parse with serde_json::from_str::<Config>(&json).
Which crates does the output need?+
serde with the derive feature for the Serialize and Deserialize derives, and serde_json to parse — or any other serde format crate.
Can I remove the example comment at the top?+
Yes. Turn off “Leading Comments” in the Rust options.
What if my samples have different fields?+
Paste several samples as JSON Lines (one JSON value per line) or as an array of objects. They are merged into one type, and fields missing from some samples become optional.
Can I paste a JavaScript object from the console?+
Yes. Unquoted keys, single quotes, trailing commas and comments are repaired automatically before the types are generated.
Is my data uploaded?+
No. The conversion runs entirely in your browser, in a background thread. Nothing is sent to a server.
Why don’t I see enums or date types?+
By default, string fields stay strings so the output matches your JSON exactly. Turn on “Detect enums” or “Detect dates” under Options to generate enum and date types.
Code generation uses quicktype (Apache-2.0 license).