JSON to RustONLINE

Generate Rust types or models from sample JSON and download .rs code.

1 MiB per input · Ctrl / ⌘ + Enter to run

quicktype infers shapes from a sample up to 128 Ki characters. Review field optionality, names, and type choices before adding generated code to your project.

Result
Ready. Paste input, then run the tool.
Your JSON stays in your browser. Core processing happens locally.
THE PRACTICAL GUIDE

Generate Rust models and review their Serde mapping

JSON to Rust generates a draft set of types for a JSON sample. It can speed up the first pass of modeling nested records in a Rust project.

When should you use it?

  • Sketch types for an API client.
  • Compare fixture fields against a Serde model.
  • Identify arrays and nullable values in nested data.
WORKED EXAMPLE

Example: infer Rust fields from JSON

This abbreviated example shows the inferred name and active fields in Rust. The full generated file includes imports and helpers and may change with generator versions; review it before adding it to a project.

Sample JSON
{"name":"Alex","active":true}
Illustrative model excerpt
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
    pub name: String,
    pub active: bool,
}

Connect Rust field names to the JSON contract

Rust naming conventions can differ from API property names. Review the generated Serde attributes, imports, and helper functions together so renaming a field does not change the wire contract. Nested objects and arrays can become named structs and vectors, which makes a complex response easier to use than unstructured field lookups.

Choose the right representation for uncertain values

Option types, numeric ranges, and enum variants need representative samples and a known contract. A field that is always populated in one response may still be absent in another. Review values that can change type or exceed an integer range, and test deserialization in your actual crate setup. The generator does not compile the result against your dependency versions on this page.

IN PRACTICE

How do I generate Rust structs for a JSON API response?

Generate Rust source from a representative sample and inspect the Serde-derived model. The tool infers observed names and types, which is useful for prototyping deserialization before refining field renames and optional values.

Illustrative Rust Serde model

rust
use serde::{Serialize, Deserialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
    pub name: String,
    pub active: bool,
}

Add the required crates in your project and review integer widths, Option fields, and naming conventions.

That response may omit a field, contain null, or use another type not represented in the sample. Update the model after testing multiple real shapes.

BEFORE YOU USE THE RESULT

What should you check before using the result?

Check crate dependencies, derives, field renames, Option choices, lifetimes, and numeric widths before compiling. Runtime behavior depends on your deserializer.

Understand JSON syntax

Technical reference: quicktype model generation documentation

THE JSON FIELD GUIDE
All guides