Generate Rust Structs from API Response
This example generates Rust structs with serde derives from a typical REST API response. The pre-filled JSON represents a user object with nested address, array of roles, and array of post objects. Switch to Rust mode to see the generated structs.
What You Get
The tool produces:
- A root
Rootstruct with all top-level fields RootAddressstruct for the nested address objectRootPostsItemstruct for array items#[derive(Serialize, Deserialize)]on every struct#[serde(rename)]attributes for keys that differ from snake_case field namesOption<T>for optional fields (likePostsitems missingLikes)- Rust type mappings:
String,i64,bool,Vec<String>,serde_json::Value
How to Use
- The example loads with a sample API response and Rust mode pre-selected
- Inspect the generated Rust structs and their serde attributes
- Copy the structs and paste them into your Rust project
- Replace with your actual API response to generate structs for your endpoints
Real-World Pattern
Rust structs with serde derives are the standard way to deserialize API responses in Rust. The generated code works directly with serde_json::from_str and serde_json::from_value. Use Option<T> for fields that may not always be present in the response.