JSON Parser

JSON to Rust Struct Converter Online

Paste any JSON and get ready-to-use Rust types in one click. Nested objects, arrays, optional fields and awkward key names are handled for you, and everything runs in your browser, so API responses and sample payloads are never uploaded.

How to convert JSON to Rust

  1. Paste your JSON, or click Upload to load a file. Use a sample that includes every field, since the types are inferred from it.
  2. Set the Root class name if you want something other than Root.
  3. Review the output on the right and click Copy.

Example

JSON input

{
  "id": 1,
  "name": "Alice",
  "active": true,
  "score": 98.5,
  "tags": ["admin"],
  "address": { "city": "New York" }
}

Rust output

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct Root {
    pub id: i64,
    pub name: String,
    pub active: bool,
    pub score: f64,
    pub tags: Vec<String>,
    pub address: Address,
}

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

JSON to Rust type mapping

JSONRust
stringString
whole numberi64
decimal numberf64
booleanbool
arrayVec<T>
objecta struct
null / unknownserde_json::Value

Naming and structure

Fields are snake_case. If the result is a Rust keyword (like type) it gets a trailing underscore, and #[serde(rename = "original")] keeps deserialization working.

  • Fields that are null or missing in some items become Option<T>.
  • Add serde (with the derive feature) and serde_json to Cargo.toml.
  • When an array contains objects, their fields are merged: a field missing from some items is treated as optional, and a field that is a whole number in one item and a decimal in another becomes a decimal.
  • The top-level JSON can be an object or an array of objects.

Using the generated types

let root: Root = serde_json::from_str(&data)?;

Related tools

Describe the same data with the JSON Schema generator, get TypeScript interfaces, create a SQL table, fix broken input with JSON Repair, or compare payloads with JSON Diff.

Frequently asked questions

How do I convert JSON to a Rust struct?
Paste your JSON and copy the code. Objects become pub structs deriving Debug, Serialize and Deserialize, arrays become Vec<T>, whole numbers become i64 and decimals become f64.
How are Rust keywords and odd key names handled?
Field names are converted to snake_case. If the result is a Rust keyword (like type) it gets a trailing underscore, and a #[serde(rename = "original")] attribute keeps deserialization working.
What about null and missing fields?
Fields that are null or missing in some array items become Option<T>. Values whose type cannot be inferred use serde_json::Value. Add serde and serde_json to Cargo.toml. Everything runs in your browser — your JSON is never uploaded to a server.
Handles JSON files up to 20MB smoothly