How to use the JSON to Rust Struct
Generate serde-ready Rust structs in seconds:
1
Paste your JSON
Paste any JSON object from your API response, config file, or Postman into the input panel.
2
Set struct name
Enter the root struct name in PascalCase (e.g. ApiResponse, UserProfile). Nested struct names are inferred automatically.
3
Click Generate
Get Rust structs with #[derive(Debug, Clone, Serialize, Deserialize)] and #[serde(rename)] attributes where needed.
4
Add serde to Cargo.toml
Copy the generated Cargo.toml snippet: serde = { version = "1", features = ["derive"] } and serde_json = "1".
When to use this tool
Use this when building Rust applications that parse or produce JSON:
- →Building a Rust web service with Axum or Actix-web that deserializes JSON request bodies or API responses
- →Writing a Rust CLI tool that reads JSON config files or processes API data with Reqwest
- →Parsing JSON data files in a Rust data processing or ETL pipeline
- →Adding serde-compatible types to a Rust library that handles external JSON from third-party APIs
- →Prototyping Rust models quickly from Postman or Swagger example JSON payloads
- →Setting up typed structs for serde_json::from_str() without writing boilerplate by hand
Frequently asked questions
Q:What Rust types are inferred from JSON values?
Strings become String, integers become i64, floats become f64, booleans become bool, null fields become Option<String> (update the inner type as needed), arrays become Vec<T>, and nested objects become separate named structs.
Q:Are serde rename attributes generated automatically?
Yes. Fields get #[serde(rename = "originalKey")] only when the JSON key differs from the snake_case Rust field name. When all keys in an object are already snake_case, #[serde(rename_all = "snake_case")] is emitted at the struct level instead.
Q:How are null values handled?
JSON null fields are typed as Option<String>. This is the idiomatic Rust pattern for nullable fields with serde — serde_json will deserialize absent or null fields correctly. Update the inner type from String to the appropriate concrete type.
Q:Are nested objects and arrays of objects supported?
Yes. Nested JSON objects generate separate named Rust structs referenced by the parent. Arrays of objects become Vec<StructName> with a dedicated struct for the item type. Empty arrays fall back to Vec<serde_json::Value>.
Q:Does the output work with Axum and Actix-web?
Yes. The generated structs derive Serialize and Deserialize from serde, making them directly compatible with Axum's Json<T> extractor, Actix-web's web::Json<T>, and any other framework that uses serde for JSON handling.
Q:What Cargo.toml dependencies do I need?
Add serde = { version = "1", features = ["derive"] } and serde_json = "1" to your [dependencies]. The Cargo.toml snippet is shown automatically after generating your structs.