Dad’s Data formats tools

JSON → Rust

Generate Rust structs with serde derives from JSON — snake_case fields, Option<T> for nullables, Vec<T> for arrays. 100% local.

JSON Input
Root struct name
Rust Output
Paste JSON to generate Rust structs.

How Struct Inference Works

The inferrer walks your JSON and produces idiomatic Rust structs with serde derives. Each JSON object becomes a pub struct with #[derive(Debug, Clone, Serialize, Deserialize)]. Field names are converted from camelCase or snake_case JSON keys to Rust's snake_case convention. When the Rust field name differs from the JSON key, a #[serde(rename = "...")] attribute is emitted automatically. Null values produce Option<T> fields.

Input
{
  "user": {
    "id": 1,
    "name": "Alice",
    "email": "[email protected]",
    "score": 9.5,
    "tags": ["rust", "backend"],
    "address": {
      "city": "Zurich",
      "country": "CH"
    },
    "deleted_at": null
  },
  "total": 42,
  "active": true
}
Output
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
    pub user: User,
    pub total: i64,
    pub active: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User {
    pub id: i64,
    pub name: String,
    pub email: String,
    pub score: f64,
    pub tags: Vec<String>,
    pub address: Address,
    #[serde(rename = "deleted_at")]
    pub deleted_at: Option<serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Address {
    pub city: String,
    pub country: String,
}

Type Mapping

JSON valueRust typeNotes
"string"StringOwned heap string
42 (integer)i64No decimal point, within int64 range
3.14 (decimal)f64Number with decimal point
true / falseboolBoolean literal
nullOption<T>Nullable field — None when JSON value is null
["a", "b"]Vec<String>Homogeneous array infers element type
[1, "a"]serde_json::ValueMixed-type arrays fall back to Value
{} or { ... }Named structNested objects become separate named structs
[] (empty)Vec<serde_json::Value>Empty array — element type cannot be inferred
Tip: When a JSON key contains characters not valid in a Rust identifier (like hyphens), or when camelCase conversion changes the name, a #[serde(rename = "originalKey")] attribute is added so serde correctly maps the JSON field to your Rust field during deserialization.

Limitations to Know

Warning: Inference is based on the sample you provide. If a field is null in your sample but carries a real type at runtime, the generated Option<serde_json::Value> will need to be replaced with the correct type (e.g., Option<String>). Verify the generated structs against your API documentation before using them in production code.

Try It

Interactive — edit the input to see the output update
Try it
Result

Frequently Asked Questions

Your files stay on your computer. Dad promised.

Data formats tools

Search the Data formats tools