JSON to Rust Struct Converter screenshot

JSON to Rust Struct Converter

Turn a JSON sample into a Rust struct in your browser. Optional and nullable fields are kept apart, and nothing is uploaded.

Privacy First
0 Runs
Updated 2026-11-06
No upload
Instant
No signup

What the JSON to Rust generator does

Each object becomes a struct deriving Serialize and Deserialize. A key that is not a valid snake_case identifier gets a serde rename attribute, and a key that is missing from some array elements also gets serde default and skip_serializing_if, so a round-trip does not invent a key the input never had. A null-only field becomes Option<serde_json::Value>, not a guess at a concrete type.

How to use it

JSON to Rust Struct Converter: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the Rust struct below.

Worked example

Input:

{
  "id": 42,
  "displayName": "Ada Lovelace",
  "active": true,
  "score": 9.5,
  "tags": [
    "math",
    "engine"
  ],
  "address": {
    "city": "London",
    "country": "GB"
  },
  "projects": [
    {
      "name": "Analytical Engine",
      "year": 1843
    },
    {
      "name": "Note G",
      "year": 1843,
      "notes": "first published algorithm"
    }
  ],
  "nickname": null
}

Output:

// Generated from a JSON sample in the browser by AllTools — nothing was uploaded.
// Rename and adjust to taste; the shape is inferred from one example, not a schema.

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
    pub id: i64,
    #[serde(rename = "displayName")]
    pub display_name: String,
    pub active: bool,
    pub score: f64,
    pub tags: Vec<String>,
    pub address: Address,
    pub projects: Vec<Project>,
    pub nickname: Option<serde_json::Value>,
}

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

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Project {
    pub name: String,
    pub year: i64,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub notes: Option<String>,
}

Why it runs in your browser

The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads JSON and returns Rust struct; reloading the page discards both.

Each object becomes a struct deriving Serialize and Deserialize. A key that is not a valid snake_case identifier gets a serde rename attribute, and a key that is missing from some array elements also gets serde default and skip_serializing_if, so a round-trip does not invent a key the input never had. A null-only field becomes Option<serde_json::Value>, not a guess at a concrete type.

Turn a JSON sample into a Rust struct in your browser. Optional and nullable fields are kept apart, and nothing is uploaded.

How to use it

JSON to Rust Struct Converter: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the Rust struct below.

Why it runs in your browser

The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads JSON and returns Rust struct; reloading the page discards both.

What to Expect

Best for

  • Converting JSON to Rust struct when the data is already on screen.

What this tool keeps

  • Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere.

Sample input

{ "id": 42, "displayName": "Ada Lovelace", "active": true, "score": 9.5, "tags": [ "math", "engine" ], "address": { "city": "London", "country": "GB" }, "projects": [ { "name": "Analytical Engine", "year": 1843 }, { "name": "Note G", "year": 1843, "notes": "first published algorithm" } ], "nickname": null }

Sample output

// Generated from a JSON sample in the browser by AllTools — nothing was uploaded. // Rename and adjust to taste; the shape is inferred from one example, not a schema. use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Root { pub id: i64, #[serde(rename = "displayName")] pub display_name: String, pub active: bool, pub score: f64, pub tags: Vec<String>, pub address: Address, pub projects: Vec<Project>, pub nickname: Option<serde_json::Value>, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Address { pub city: String, pub country: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Project { pub name: String, pub year: i64, #[serde(default, skip_serializing_if = "Option::is_none")] pub notes: Option<String>, }

Frequently asked questions

How do I use the json to rust struct converter?

JSON to Rust Struct Converter: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the Rust struct below.

Is my input uploaded?

No. The text is parsed on this page with JavaScript and is never posted to a server.

Is there a size limit?

Yes: 5 MB per run. Larger input is refused with a message rather than freezing the tab.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.