Skip to content
ToolMug

JSON to Rust Struct Converter

Paste JSON and get Rust structs ready for serde_json. Fields use snake_case with rename attributes where needed, optional or nullable values become Option, and nested objects get their own structs.

Runs in your browser — nothing you enter is uploaded

How to use

  1. Paste a JSON sample, or click Load sample.
  2. Set the name of the root struct.
  3. Copy or download the code. Add serde with the derive feature and serde_json to Cargo.toml.

Options explained

Root type name
Name of the top-level struct. Nested structs are named after their keys.

Examples

{"userName": "ada", "type": "admin"} becomes:

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
    #[serde(rename = "userName")]
    pub user_name: String,
    pub r#type: String,
}

Frequently asked questions

Which crates do I need?

serde with the derive feature, and serde_json to parse. serde_json::Value is used for values whose type cannot be inferred.

How are Rust keywords handled?

Keys such as type become raw identifiers (r#type). serde removes the r# prefix, so no rename is needed.

What number types are used?

i64 for whole numbers and f64 for numbers with decimals.

Is my JSON uploaded?

No. The types are generated in your browser, so API responses with real data stay on your device.

Privacy

This tool runs entirely in your browser. Your files and text are processed on your device and are never uploaded to our servers.

Related tools