JSON to Rust Struct (serde)

Generate Rust structs with serde Serialize/Deserialize derives from JSON. Nested objects become nested structs; snake_case fields get auto #[serde(rename = ...)] when the original key isn't snake_case. Add to your project after running cargo add serde --features derive and cargo add serde_json.

How to use the JSON to Rust Struct (serde)

Paste JSON. Output includes the serde imports at the top. Date strings become chrono::DateTime<chrono::Utc> — add chrono to Cargo.toml or change to String if you don't need date typing.

Generating Rust structs from JSON

serde is how Rust handles JSON, and it works from structs that mirror the data — but deriving those structs by hand means naming every field, choosing a type, and adding a #[serde(rename = ...)] wherever a JSON key is not valid snake_case. Get one type wrong and the compiler rejects the whole thing.

This generates Rust structs from a JSON sample with #[derive(Serialize, Deserialize)], nesting a struct per nested object and adding rename attributes where keys need them, with the serde imports included. Date strings become chrono::DateTime<chrono::Utc>, so add chrono to Cargo.toml or change those to String. Run cargo add serde --features derive and cargo add serde_json first. The Go generator takes the same approach for that language.

Common use cases

  • serde structs — generate structs with Serialize and Deserialize derives.
  • Rename keys — get #[serde(rename)] where a key is not snake_case.
  • Typed dates — map ISO date strings to chrono::DateTime.
  • Nested structs — produce a struct for each nested object.
  • Scaffold a client — build request and response types from a sample.

Frequently asked questions

What derives does it add?

Each struct gets #[derive(Serialize, Deserialize)], and the serde imports are included at the top.

How are non-snake_case keys handled?

They get a #[serde(rename = ...)] attribute so the Rust field can stay idiomatic.

What happens to date strings?

They become chrono::DateTime<chrono::Utc> — add chrono to Cargo.toml, or change them to String if you do not need date typing.

What do I need to add to my project?

Run cargo add serde --features derive and cargo add serde_json before using the generated structs.
Embed this tool on your site

Free to embed, no attribution required (but appreciated). Paste this where you want the tool to appear: