{ JSON to Rust Struct }

// convert json into typed rust structs with serde

Convert JSON samples into Rust struct definitions with serde derive macros. Generate clean, idiomatic Rust code with nested structs, Option types, and Vec support instantly.

Paste any JSON object or array
๐Ÿฆ€

Ready to generate

Paste your JSON and click Generate

HOW TO USE

  1. 01
    Paste your JSON

    Drop any JSON object or array into the input panel โ€” nested structures are fully supported.

  2. 02
    Configure options

    Set a root struct name, choose derive macros, and toggle serde rename or Option wrapping.

  3. 03
    Copy Rust code

    Click Generate, then copy the complete struct definitions ready to drop into your Rust project.

FEATURES

serde Derive Nested Structs Vec<T> Arrays Option<T> PascalCase Names snake_case Fields

USE CASES

  • ๐Ÿฆ€ Rapid API response modeling
  • ๐Ÿ”ง Config file deserialization
  • ๐Ÿ“ฆ REST client data types
  • ๐Ÿงช Prototyping Rust data models

WHAT IS THIS?

This tool converts JSON samples into idiomatic Rust struct definitions. It automatically infers field types, generates serde derive macros, handles nested objects as separate structs, and maps JSON arrays to Vec<T> โ€” saving hours of manual boilerplate writing.

RELATED TOOLS

FREQUENTLY ASKED QUESTIONS

What serde crate do I need?

Add serde = { version = "1", features = ["derive"] } to your Cargo.toml. If you want JSON specifically, also add serde_json = "1".

How are JSON null values handled?

JSON null values are mapped to Option<serde_json::Value>. You can also enable the "All fields Option" toggle to wrap every field in Option<T> for maximum flexibility.

What happens with mixed-type arrays?

Arrays with mixed types (e.g. numbers and strings) are typed as Vec<serde_json::Value> to safely represent any JSON value without losing data.

Does it handle deeply nested JSON?

Yes โ€” nested objects are recursively converted into separate named structs. Each nested struct gets a PascalCase name derived from its parent field name, keeping your code organized.

What does serde rename_all do?

When enabled, #[serde(rename_all = "camelCase")] is added so that snake_case Rust field names automatically map to camelCase JSON keys during serialization and deserialization.

Is my JSON data sent to a server?

No โ€” all processing happens entirely in your browser using JavaScript. Your JSON never leaves your machine. It's 100% client-side and private.

What is a JSON to Rust Struct Converter?

A JSON to Rust Struct converter is a developer tool that reads a JSON sample and automatically generates the corresponding Rust data structures. Instead of manually analyzing field names, inferring types, and writing boilerplate #[derive] annotations, you simply paste your JSON and get production-ready Rust code in seconds. This is especially valuable when working with third-party REST APIs, configuration files, or any serialized data format where the schema is defined in JSON.

๐Ÿ’ก Looking for premium web development assets? MonsterONE offers unlimited downloads of templates, UI kits, and developer assets โ€” worth checking out.

How the Rust Struct Generator Works

The converter performs a recursive traversal of your JSON structure. For each JSON object encountered, it creates a corresponding Rust struct with typed fields. The type inference follows these rules:

Understanding serde Derive Macros

Rust's serde crate is the de-facto standard for serialization and deserialization. Using procedural derive macros, you can annotate your structs so that serde knows how to convert them to and from formats like JSON. The most common derives are:

Together, these macros eliminate the need to implement serialization logic by hand, making Rust API development dramatically faster.

The rename_all Attribute

JSON APIs typically use camelCase field names (e.g., firstName, createdAt), while idiomatic Rust uses snake_case (e.g., first_name, created_at). The #[serde(rename_all = "camelCase")] attribute bridges this gap automatically โ€” your Rust code stays idiomatic while the JSON mapping remains correct. This tool adds this attribute for you when the option is enabled.

Option<T> for Nullable Fields

In JSON APIs, fields can sometimes be missing or null โ€” especially in partial update responses or optional response fields. Wrapping a type in Option<T> tells serde to treat the field as optional: None when the key is absent or null, and Some(value) when present. The "All fields Option" toggle in this tool wraps every generated field in Option, which is a safe default for API responses where the schema might not be perfectly consistent.

Working with Nested Structures

One of the most powerful features of this converter is its handling of nested JSON objects. For example, if your JSON has a user object containing an address object, the tool generates two separate Rust structs: User and Address, with the User struct holding an address: Address field. This mirrors how you'd structure the types in real Rust code, keeping everything modular and type-safe.

Vec<T> for JSON Arrays

JSON arrays map naturally to Rust's Vec<T>. The converter examines the contents of each array to determine the element type. If all elements are strings, it generates Vec<String>. If they're objects, it creates a new struct for the element type and generates Vec<ElementName>. Mixed-type arrays fall back to Vec<serde_json::Value> for flexibility.

Setting Up serde in Your Rust Project

To use the generated code in your project, add the following to your Cargo.toml:

[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"

Then add use serde::{Deserialize, Serialize}; at the top of your Rust file. The generated structs will compile immediately and work with serde_json::from_str() and serde_json::to_string().

Why Use This Tool?

Writing Rust structs from JSON by hand is tedious and error-prone, especially for large API responses with dozens of nested fields. This tool eliminates that friction, letting you focus on writing application logic instead of boilerplate. Whether you're building a REST client, parsing configuration, or prototyping data models, the JSON to Rust Struct converter accelerates your workflow and reduces mistakes.

โ˜•