JSON to Rust — Generate Serde Structs
Generate Rust struct definitions with serde derive macros from JSON. Handle nested types and snake_case conversion.
JSON Input
Rust Structs
About JSON to Rust Structs Generator
Rust's type system and serde ecosystem make it one of the safest languages for JSON handling — but manually writing struct definitions for every API response is tedious and error-prone. Our JSON to Rust converter analyzes your JSON data, infers Rust types (String, i32, i64, f64, bool, Vec<T>, Option<T>), generates structs with #[derive(Serialize, Deserialize)], and automatically converts camelCase JSON keys to snake_case with #[serde(rename)] attributes. The output is ready to paste into your Rust project and use with serde_json, reqwest, or any serde-compatible library.
How to Use JSON to Rust Structs Generator
Paste Your JSON
Paste a JSON object or array into the input editor. The tool examines each value to determine whether it should be String, i32, i64, f64, bool, Vec, Option, or a nested struct.
Configure Struct Options
Set the root struct name and choose whether to include serde derive macros. Toggle snake_case conversion and decide between separate or inline nested structs.
Copy or Download Rust Code
Review the generated structs in the output panel, then copy to clipboard or download as a .rs file. The code includes all necessary derive macros and serde attributes.
Common Use Cases
API Client Development
Paste JSON responses from REST APIs and generate Rust structs for use with reqwest, hyper, surf, or ureq. The structs deserialize directly with serde_json::from_str() or response.json().
Configuration File Parsing
Create typed structs for JSON config files and deserialize them with serde_json. Type-safe configuration prevents runtime errors from missing or mistyped settings.
WebAssembly Data Types
Generate Rust structs for Wasm projects that parse JSON from JavaScript via wasm-bindgen or serde-wasm-bindgen. The generated types ensure correct serialization across the JS/Wasm boundary.
CLI Tool Development
Build Rust CLI tools that consume JSON APIs or parse JSON files. Generate structs from sample data and use them with clap, serde_json, and other ecosystem crates.
Actix/Axum Web Handlers
Generate request and response structs for Actix Web or Axum handlers. The serde derives enable automatic JSON serialization and deserialization in your web routes.
Why Use Our JSON to Rust Structs Generator?
Serde Integration
Generates #[derive(Serialize, Deserialize)] with proper #[serde(rename)] attributes, ready for serde_json, reqwest, and other serde-compatible crates
Automatic Snake Case
Converts camelCase and PascalCase JSON keys to Rust snake_case naming, adding rename attributes so deserialization works correctly
Nested Struct Generation
Deeply nested JSON objects produce separate named structs, keeping your code modular and reusable across multiple endpoints
Accurate Type Inference
Integers are mapped to i32 or i64 based on magnitude, decimals to f64, strings to String, booleans to bool, and null values to Option<T>
Array Handling
JSON arrays produce Vec<T> with the element type inferred from the first item. Empty arrays become Vec<serde_json::Value>
Privacy-First
Your JSON data never leaves your browser. Safe for internal APIs, production responses, and any data containing secrets or PII
Key Features
#[derive(Serialize, Deserialize)] with serde derive macros
Automatic snake_case conversion with #[serde(rename = "originalKey")]
Nested struct generation with proper naming
Vec<T> for arrays with element type inference
Option<T> for nullable fields
i32/i64/f64/bool/String type inference from JSON values
Optional #[derive(Debug, Clone)] annotations
Configurable root struct name
Download as .rs file
100% client-side processing — no data leaves your browser
100% Client-Side Processing
Your data never leaves your browser
All processing happens in your browser using JavaScript. Your data is never sent to our servers or any third party. Safe for sensitive data, API keys, and production configs.
Frequently Asked Questions
Quick answers to common questions about json to rust structs generator
Yes. CamelCase JSON keys (like "firstName") are converted to snake_case (first_name) for Rust field names, and a #[serde(rename = "firstName")] attribute is added so deserialization maps correctly. Alternatively, you can use #[serde(rename_all = "camelCase")] at the struct level — the generated code uses per-field renames for explicitness.
JSON null values are mapped to Option<String> by default. You may need to adjust the inner type based on your data — for example, Option<i32> if the field is sometimes a number and sometimes null. Serde handles Option fields gracefully, treating missing JSON fields as None.
Yes. Toggle off the serde option to generate plain structs with only #[derive(Debug, Clone)]. This is useful if you are using a different serialization library or only need the struct definitions for internal data modeling.
Integer values within the i32 range (-2,147,483,648 to 2,147,483,647) are mapped to i32. Larger values use i64. If your API returns large IDs (like Twitter snowflake IDs), the tool correctly uses i64. You can also manually change to u32, u64, or usize after generation.
Yes. Each nested JSON object produces a separate named Rust struct. For example, {"user": {"address": {"city": "NYC"}}} generates struct Root, struct User, and struct Address, each with appropriate fields and types. The nesting depth is unlimited.
Absolutely. The generated structs work directly with reqwest's .json::<MyStruct>() method. Since the structs derive Deserialize, reqwest can automatically parse JSON responses into your typed structs. Just add reqwest and serde as dependencies in your Cargo.toml.
The generator creates struct fields only. Rust enums (for tagged unions or discriminated types) need to be manually created. If your JSON has a "type" discriminator field, consider using #[serde(tag = "type")] on a manually defined enum after generation.
Related JSON Tools
JSON to Go Struct
→
Generate Go structs — a similar workflow for Go developers
JSON to Proto
→
Generate Protocol Buffer definitions for Rust prost/tonic gRPC services
JSON to TypeScript
→
Generate TypeScript interfaces for frontend clients alongside your Rust backend
JSON to Kotlin
→
Generate Kotlin data classes for Android/KMP clients calling your Rust API
JSON Formatter
→
Format and validate JSON before generating Rust structs