Skip to content

JSON to Rust Struct

Generate serde-ready Rust structs from a sample JSON document.

Needs serde = { version = "1", features = ["derive"] } in your Cargo.toml. The rename attribute appears only where the snake_case name differs from the JSON key.

Quick Tool Overview

The JSON to Rust Struct converter writes serde-ready structs: a derive line with Serialize and Deserialize, snake_case fields, rename attributes only where the name actually differs, and Option<T> for keys that can be absent.

What it does
Generates serde-compatible Rust structs from JSON
You give it
A JSON payload, ideally an array of records
You get back
Struct declarations ready for serde_json
Best for
Deserialising an API response in a Rust service or CLI
Developer Tools Free, unlimited use No sign-up Runs in your browser

About the JSON to Rust Struct

Paste a payload and get the structs, ready for serde: a derive line with Serialize and Deserialize, fields renamed to snake_case, and a serde rename attribute wherever the Rust name differs from the JSON key — and only where it differs, so the output stays readable.

Optional keys become Option<T>, which is how Rust represents a value that may not be there, and nested objects become their own structs declared alongside. Numbers are typed i64 or f64 depending on whether any decimal appears in the sample, and a value the sample cannot pin down falls back to serde_json::Value rather than guessing wrongly.

Key features of the JSON to Rust Struct

Rename only where needed

The serde attribute appears exactly where the snake_case Rust name differs from the JSON key, so the output stays readable.

Option for optional keys

A key missing anywhere in the sample becomes Option<T>, because serde returns an error rather than a default when a required field is absent.

Configurable derives

Add Default, PartialEq or Clone to the derive line to match whatever your crate needs.

Honest fallbacks

A field the sample cannot pin down becomes serde_json::Value rather than a wrong concrete type that fails at runtime.

Nested structs declared

Each nested object becomes its own named struct, so the whole payload is typed rather than half-typed.

How to use the JSON to Rust Struct

  1. 1

    Paste the JSON

    An array of records gives better detection of optional fields.

  2. 2

    Name the root struct

    Nested structs are named from the keys holding them.

  3. 3

    Adjust the derives

    Add or remove traits such as Default or PartialEq to match your crate.

  4. 4

    Copy into your crate

    Paste into a .rs file; add serde with the derive feature to Cargo.toml.

Frequently asked questions

serde with the derive feature and serde_json: serde = { version = "1", features = ["derive"] } and serde_json = "1".

Reviews of the JSON to Rust Struct

What people who use the JSON to Rust Struct think of it. Reviews come from visitors and are posted as written.

No ratings yet

Yours would be the first.

  • 5 0 reviews rated 5 stars
  • 4 0 reviews rated 4 stars
  • 3 0 reviews rated 3 stars
  • 2 0 reviews rated 2 stars
  • 1 0 reviews rated 1 star

Write a review

Used this tool? Your rating helps the next person decide.

Your rating

Plain text only — links, email addresses and HTML are not accepted. Your name and review are shown publicly; nothing else is collected. See the privacy policy.

0 reviews

Newest first

No reviews yet

Be the first to rate the JSON to Rust Struct. It takes half a minute and no account.

Write the first review

More developer tools