JSON to Rust Serde Struct Converter
Instantly convert JSON objects and arrays into type-safe Rust structs with Serde derive macros. Supports reserved keyword safety, Option types, Chrono dates, and custom naming conventions.
// Generated by Nazamos (https://nazamos.com/json-to-rust)
// 100% Client-Side & Privacy-First Developer Suite
use serde::{Serialize, Deserialize};
use chrono::{DateTime, Utc};
use uuid::Uuid;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[serde(rename_all = "camelCase")]
pub struct UserProfile {
pub bio: String,
pub location: String,
pub github: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[serde(rename_all = "camelCase")]
pub struct UserStats {
pub stars_count: i64,
pub rating: f64,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[serde(rename_all = "camelCase")]
pub struct User {
pub id: i64,
pub user_name: String,
pub email: String,
pub is_verified: bool,
pub roles: Vec<String>,
pub created_at: DateTime<Utc>,
pub profile_id: Uuid,
pub profile: UserProfile,
pub stats: UserStats,
}100% Zero-Egress Privacy
Never paste production API tokens or enterprise customer data into ad-heavy remote servers. Nazamos runs 100% locally in your browser with zero network requests.
Compile-Ready Rust Code
Handles all 39 Rust reserved keywords (`type`, `match`, `ref`), integer vs float precision, and recursive nested structs with idiomatic PascalCase naming.
Modern Backend Support
First-class support for chrono::DateTime<Utc>, uuid::Uuid, and seamless integration with web frameworks like Axum, Actix-web, and reqwest.
JSON to Rust Serde: Type System Mapping
How Nazamos maps dynamic JSON types into Rust's strict compile-time type system:
| JSON Data Type | Inferred Rust Type | Serde Attribute / Notes |
|---|---|---|
| String ("hello") | String | Standard heap-allocated UTF-8 string |
| Integer (42, -100) | i64 | 64-bit signed integer (prevents overflow on IDs & timestamps) |
| Float (19.99, 3.14) | f64 | Double-precision IEEE 754 floating point |
| Boolean (true / false) | bool | Standard 1-byte boolean |
| ISO-8601 Date ("2026-09-09T...") | DateTime<Utc> | Requires `chrono` crate with serde feature enabled |
| UUID ("a0eebc99-...") | Uuid | Requires `uuid` crate with serde feature enabled |
| Null / Missing Field | Option<T> | `#[serde(skip_serializing_if = "Option::is_none")]` |
| Array ([1, 2, 3]) | Vec<T> | Dynamically sized vector with homogeneous items |
| Nested Object ({"sub": {…}}) | ChildStruct | Extracted into a separate named PascalCase struct |
| Keyword ("type", "match") | r#type / r#match | Safe Rust raw identifier with `#[serde(rename = "...")]` |
1. Add Dependencies to Cargo.toml
Copy and paste these dependencies into your Rust project's Cargo.toml file:
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
chrono = { version = "0.4", features = ["serde"] } # Optional: For DateTime<Utc>
uuid = { version = "1.0", features = ["serde", "v4"] } # Optional: For Uuid2. Deserializing in Production (Axum & serde_json)
Example showing how to parse JSON strings and use generated structs inside an Axum API handler:
use serde::{Deserialize, Serialize};
// Generated struct from Nazamos
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct User {
pub id: i64,
pub user_name: String,
pub is_verified: bool,
}
// 1. Direct parsing from a string
fn parse_example() -> Result<(), Box<dyn std::error::Error>> {
let json_data = r#"{"id": 1042, "userName": "alex", "isVerified": true}"#;
let user: User = serde_json::from_str(json_data)?;
println!("Parsed User: {:#?}", user);
Ok(())
}
// 2. Axum API handler example
// async fn create_user(axum::Json(payload): axum::Json<User>) -> axum::response::Json<User> {
// println!("Received user: {:?}", payload);
// axum::Json(payload)
// }