JSON to Rust struct generator
About JSON to Rust
The JSON to Rust generator converts sample payloads into nested structs for API clients, CLI apps and service integrations. Arrays map to Vec, missing or null members to Option, integers to i64, decimals to f64 and strings to owned String values.
Serde mode adds Serialize and Deserialize derives, plus rename attributes for JSON keys that are not valid Rust field names. Field names use snake_case and reserved words use raw identifiers. Arrays of objects are merged, so the model covers more than the first element.
Runs in your browser. Nothing is uploaded. The generator only infers what the pasted values show. Before you use the model in production, review integer ranges, borrowed versus owned data, tagged enums, timestamps and custom deserializers.
How it works
Map JSON shapes to Rust types
Strings become String, booleans become bool, whole numbers become i64 and decimals become f64. Arrays become Vec<T>, nested objects become separate structs, and explicit nulls wrap the type in Option<T>.
Detect optional array-object fields
The generator merges every object in an array. A key missing from any element becomes Option<T>. Numbers widen from i64 to f64 when the samples mix both. Element types that do not fit together use a conservative fallback.
Generate Serde-ready models
With Serde on, structs derive Debug, Clone, Serialize and Deserialize. Rename attributes keep original keys such as display-name after the field name is cleaned up. Mixed or unknown values use serde_json::Value, which needs serde_json.
Control field visibility
Public fields are handy for plain data structs. Turn them off when you want private state and plan to add constructors, accessors or validation yourself.
Frequently asked questions
Which Cargo dependencies does Serde mode require?
Add serde with its derive feature. If the output uses serde_json::Value because a sample was empty or mixed, add serde_json too. Turn Serde mode off if you only want plain struct definitions.
Why does a field use Option?
The JSON value was null, or the key was missing from at least one object in a sampled array. A single object cannot show which keys may be absent in other responses, so check the API contract.
Does the tool infer Rust enums or chrono dates?
No. JSON carries no enum or timestamp type information. Strings stay String. Replace them with an enum, a chrono type, a UUID or a validated newtype when your domain rules allow it.
Does generation upload my API response?
No. Parsing and Rust code generation run in your browser.
Learn more
Sources & last verified
We checked this tool's behavior and the claims on this page against the specifications below on . The tool runs in your browser, so the output you see is exactly what the engine produced.
Found a wrong result or an outdated claim? Report an error and we will check it again.