JSON-Utils

JSON to Rust Serde Struct

Generate Rust structs that work with serde and serde_json. Nested objects become their own structs, arrays become Vec, and keys that are not valid snake_case, or that collide with Rust keywords, get a serde rename attribute so deserialization matches the original JSON. Fields the sample shows as null or sometimes missing become Option types.

JSON
Rust
Result will appear here
Ready. Press Generate or Ctrl+Enter.

How to use the JSON to Rust Serde Struct

  1. Paste a JSON sample in the left pane.
  2. Pick the integer type and the derive list your project uses.
  3. Press Generate, then copy the structs or download them as a .rs file.

Example

Try a camelCase key to see a serde rename attribute appear.

{
  "name": "json-utils",
  "version": "1.0.0",
  "private": false,
  "tags": ["json", "tools"],
  "author": { "name": "Ada", "active": true },
  "score": 9.5,
  "notes": null
}

Frequently asked questions

Why do some fields have a rename attribute?

Rust fields are snake_case and cannot be keywords. When the JSON key differs from the field name, a #[serde(rename)] attribute keeps the wire name exact.

What type do null values get?

A field that is null in the sample, or missing from some array elements, becomes Option of the inferred type. A field that is only ever null becomes serde_json::Value, since nothing else can be inferred.