Skip to main content
devtools24

JSON to Rust Struct

Generate Rust struct definitions with serde derive macros from JSON data. Includes proper type inference and rename attributes.

Input0 chars
Output
Rust struct will appear here...
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Note: Generated structs use serde for JSON serialization. Field names are converted to snake_case with appropriate #[serde(rename)] attributes.

Rust Serde - Technical Details

Serde is Rust's serialization framework. The generated structs use #[derive(Serialize, Deserialize)] for JSON support. Field names are converted to snake_case with #[serde(rename)] for original keys.

Command-line Alternative

# Add serde to Cargo.toml
cargo add serde --features derive
cargo add serde_json

# Example usage
let data: MyStruct = serde_json::from_str(json_str)?;

Reference

View Official Specification