Code Generators · Runs in your browser

JSON to Rust Struct Generator (Serde)

Paste a JSON sample and get ready-to-use Rust structs, with nested types, arrays and optional fields worked out for you. Ideal for deserializing with serde and serde_json.

JSON
Drop a file to load it
Rust
Waiting for input

How to use it

  1. Paste a representative JSON sample, such as an API response.
  2. Set the root type name and pick a style: serde structs.
  3. Copy the Rust code or download it as a file.

Serde attributes

Structs derive Serialize and Deserialize, and #[serde(rename = "…")] keeps the original key names.

Option

Fields that may be missing or null become Option<T> with #[serde(default)].

Integers vs. decimals

Number types come from how the number is written in your sample: 3 is an integer, 3.0 and 3.5 are decimals, and long IDs use a 64-bit type.