JSON to Rust Converter
Generate Rust structs from JSON. Paste your JSON:
Loading...
Loading...
Generate Rust Structs from JSON
This tool converts JSON to Rust structs with Serde derive macros for serialization and deserialization.
Example Output
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct User {
pub id: i32,
pub user_name: String,
pub is_active: bool,
}Type Mapping
| JSON | Rust |
|---|---|
| string | String |
| integer | i32 / i64 |
| decimal | f64 |
| boolean | bool |
| null | Option<String> |
| array | Vec<T> |
| object | Nested struct |
Using Generated Code
// Add to Cargo.toml:
// serde = { version = "1.0", features = ["derive"] }
// serde_json = "1.0"
let json = r#"{"id": 1, "userName": "john"}"#;
let user: User = serde_json::from_str(json)?;
println!("{:?}", user);Related Tools
- JSON to Go — Generate Go structs
- JSON to TypeScript — For web apps
- JSON Validator — Validate JSON first