Ready to generate
Paste your JSON and click Generate// 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.
Ready to generate
Paste your JSON and click GenerateDrop any JSON object or array into the input panel โ nested structures are fully supported.
Set a root struct name, choose derive macros, and toggle serde rename or Option wrapping.
Click Generate, then copy the complete struct definitions ready to drop into your Rust project.
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.
Add serde = { version = "1", features = ["derive"] } to your Cargo.toml. If you want JSON specifically, also add serde_json = "1".
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.
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.
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.
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.
No โ all processing happens entirely in your browser using JavaScript. Your JSON never leaves your machine. It's 100% client-side and private.
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.
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:
Stringi64f64boolOption<serde_json::Value>Vec<T> where T is inferred from the array's element typeRust'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:
#[derive(Serialize)] โ enables converting a Rust struct into JSON (or another format)#[derive(Deserialize)] โ enables parsing JSON into a Rust struct#[derive(Debug)] โ enables pretty-printing structs during development#[derive(Clone)] โ enables cloning struct instancesTogether, these macros eliminate the need to implement serialization logic by hand, making Rust API development dramatically faster.
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.
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.
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.
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.
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().
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.