JSON to Rust

Paste JSON and instantly get matching Rust struct definitions with serde derives, nested structs, and Vec types.

Use the JSON to Rust

JSON Input

Rust Structs

Nested objects become their own named struct, since Rust has no anonymous struct syntax.

Copied!

Summary

This tool converts sample JSON into Rust struct definitions ready for a serde-based project. It walks the JSON tree, infers a Rust type for every value, merges the fields of arrays of objects into a single struct, and writes serde derive attributes plus per-field rename tags so serde_json can parse the original JSON back into the same shape. Nested objects become their own named structs, since Rust has no anonymous struct syntax the way Go does.

How it works

  1. Paste JSON into the input box, or click "Load Sample" to try it with example data.
  2. Set a root struct name for the top-level type.
  3. The Rust struct definitions render on the right as you type.
  4. Nested objects become separate named structs; arrays of objects merge their fields into one struct.
  5. Toggle "Derive Clone" if your code needs to clone the generated structs.
  6. Click "Copy Rust Code" to copy the generated code to your clipboard.

Use cases

  • Bootstrap Rust structs for a REST API client from a sample response.
  • Type a webhook payload before writing the handler.
  • Generate structs from third-party API documentation JSON.
  • Check how serde will map a JSON shape before writing code by hand.
  • Speed up prototyping Rust services that consume external JSON.

Frequently Asked Questions

Last updated: 2026-07-13 · Reviewed by Nham Vu