{ } JSON Workbench100% Private • Zero Server Uploads

"JSON to Rust":{ }

Paste a JSON sample and get clean Rust structs. Nested objects become named types, arrays become typed collections, and nullable fields are handled. Powered by quicktype's inference engine running 100% in your browser: nothing is uploaded, so real API payloads stay on your machine.

What is a JSON to Rust converter?

Hand-writing structs for an API response is slow and error-prone. This tool infers Rust structs from a JSON sample: nested objects become named types, arrays become typed collections, and null/missing values become optional fields. It runs quicktype's inference engine entirely in your browser, so real API payloads (often containing user data or credentials) never leave your machine.

Other languages from the same JSON

The same generator also writes TypeScript, Python, Go, Java, C#, Kotlin, Swift, Dart, Ruby, PHP, Pydantic, Zod from the same sample, and a JSON Schema if you need a language-neutral contract.

Rust mapping notes

  • Structs derive Debug, Serialize and Deserialize, and every field is pub so you can use it from any module.
  • Nullable or missing fields become Option<T>; serde fills a missing key with None automatically.
  • Field names convert to snake_case. camelCase JSON gets #[serde(rename_all = "camelCase")] on the struct, and odd keys get a per-field #[serde(rename = "...")], so the original keys round-trip.

Use the structs with serde_json

Add serde (with the derive feature) and serde_json to Cargo.toml:

[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"

Then deserialize a string, or a whole HTTP response with reqwest (enable its json feature):

let root: Root = serde_json::from_str(&body)?;
println!("{:?}", root.owner.email);

// reqwest = { version = "0.12", features = ["json"] }
let root: Root = reqwest::get(url).await?.json().await?;

Writing JSON back out is serde_json::to_string(&root)?; renamed fields serialize under their original JSON keys.

Common Rust JSON pitfalls

  • Unknown keys are ignored. serde skips fields that aren't in the struct. If you want new API fields to be an error, add #[serde(deny_unknown_fields)].
  • Numbers that change type. A field that is 1 in your sample becomes i64; if the API later sends 1.5, deserialization fails. Include a decimal in the sample, or change the type to f64.
  • Dates stay strings. ISO timestamps are typed String. Parse them with chrono (DateTime<Utc> plus chrono's serde feature) if you need real date types.
  • Fields missing from your sample. Paste an array of several objects so keys that only appear sometimes are typed Option<T>.

How to use

  1. Paste a JSON sample (an API response works well) into the Input pane.
  2. Generated Rust structs appear instantly. Nested objects become their own named types.
  3. Non-standard JSON (single quotes, trailing commas, comments) is auto-repaired first.
  4. Copy the code into your project.

Examples

JSON → Rust structs

Input
{
  "id": 42,
  "name": "workbench",
  "owner": { "email": "[email protected]", "active": true }
}
Output
use serde::{Serialize, Deserialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct Root {
    pub id: i64,

    pub name: String,

    pub owner: Owner,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Owner {
    pub email: String,

    pub active: bool,
}

FAQ

How do I convert JSON to Rust types?

Paste any JSON sample. The structs are inferred from the values and nesting, entirely in your browser. Nothing is uploaded.

How are nested objects handled?

Each distinct nested object becomes its own named type, referenced from the parent, arrays of objects included.

What about optional or null fields?

Fields that are null or missing in parts of the sample are typed as optional/nullable in the generated code.

Can I paste multiple samples?

Paste an array of objects: the type is inferred from the union of all items, which catches optional fields a single sample would miss.

Which crate does the output target?

serde + serde_json, the standard Rust JSON stack. Add both to Cargo.toml and the generated structs deserialize directly.

How do I parse a JSON array into a Vec of structs?

Paste the array as your sample. The generator emits pub type Root = Vec<RootElement>;, so serde_json::from_str::<Root>(&body) returns a Vec.

Can I add Clone or PartialEq?

Yes. Extend the derive line to #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]; nothing else changes.

Is my JSON uploaded?

No. Generation runs 100% in your browser via quicktype's engine. Nothing is uploaded.

Related tools