JSON to Rust
Generate Rust structs with serde derives and Option types from JSON.
Generate Rust structs
Result: —
How to use the JSON to Rust
- Paste a JSON sample into the input box.
- Set the name of the root struct.
- Click Generate structs and copy the Rust code.
Features
- Serde derives for Debug, Serialize and Deserialize
- Snake case fields with rename attributes when needed
- Arrays become Vec types and nulls become Option types
- Objects that share a shape merge into one struct
Advertisement
Frequently Asked Questions
Common questions about the free online json to rust.
Paste a JSON sample, set the root struct name and click Generate structs. Every object shape
becomes a struct with typed public fields.
Every struct gets the derive attribute for Debug, Serialize and Deserialize, so it works with
serde without further edits.
A field that can be null becomes an Option type, while fields with mixed or unknown types use
serde_json::Value so any data still fits.
Arrays become Vec types with the matching element type, and an array that is missing from
some entries becomes an Option around the Vec.
Field names use snake case, and a serde rename attribute is added whenever the original JSON
key would not match the Rust name.
Keys such as type or match become identifiers with a trailing underscore, while the rename
attribute keeps the original JSON key working.
No. The structs are generated inside your browser, so nothing is uploaded, logged or stored
anywhere.
Invalid JSON, or a sample that is not an object or an array, produces a clear error message
instead of code.
Last updated: October 10, 2026