New 58+ tools are now available — built to keep your workflow moving.

JSON to Rust Struct Generator

Turn any JSON into ready-to-compile Rust struct definitions with serde derives.

Paste any JSON and press Run to get Rust struct definitions. Objects become structs, arrays become Vec, null becomes Option, and nested objects get their own types with serde rename attributes where a key needs escaping. Nothing is sent to storage.

Choose a file first — Run stays disabled until the file is selected.

File ready — press Run to start.

Optimizing your file…

Your result is ready — download it below:

Re-encoded without size gain Download links expire within 30 minutes.

This image appears to be already optimized — try a lower quality setting for a smaller file.
No logo or watermark was detected in the marked corners — your images were delivered unchanged.

No result to display for the current input.

JSON to Rust Struct Generator Online

Turn any JSON into ready-to-compile Rust struct definitions with serde derives.

Generate Rust Structs from JSON

Paste any JSON document and get idiomatic Rust struct definitions in seconds. The generator infers field types, wraps nulls in Option, turns arrays into Vecs, and emits nested structs for objects — with serde derives and the exact Cargo dependencies you need. Everything runs in your browser or on a server endpoint and is never stored.

How It Works

Paste a JSON document, choose a root struct name and whether to include Serialize/Deserialize derives, then press Run. The generator walks the document and creates one struct per object, named from the JSON path — address becomes Address, company.address becomes CompanyAddress. Arrays produce Vec<T>; when an array holds objects, their fields are merged across every sample so a key missing from some entries automatically becomes Option<T>.

Type Inference

Booleans map to bool, integers to i64, floats to f64 and strings to String. A null value becomes Option<T> (or Option<serde_json::Value> when the type cannot be determined). Mixed integer/float values are unified to f64; anything genuinely ambiguous falls back to serde_json::Value, which always compiles.

Valid Identifiers & Keywords

JSON keys become snake_case Rust field names automatically, so firstName becomes first_name and first-name becomes first_name. Rust keywords such as type or match are emitted as raw identifiers (r#type). When a field name differs from the original key, a #[serde(rename = "...")] attribute is added so deserialisation still matches the original JSON exactly.

Non-Object Roots

If your JSON is an array or a scalar rather than an object, the generator wraps it in a newtype struct — for example pub struct Root(pub Vec<Item>); or pub struct Root(pub String); — with the inner type defined alongside it.

Privacy & Security

Your JSON is processed only to produce the Rust code and is never stored, logged or shared. There is no upload, no account and no watermark.

Frequently asked questions

Is the generated code ready to compile?

Yes. The snippet includes the use statement and the Cargo dependencies require comment. Add serde (with the derive feature) and, when noted, serde_json to your Cargo.toml and it compiles as-is. Choose the "Debug, Clone only" option to skip serde entirely.

How are null values handled?

Fields whose value is null become Option<T>. If the type cannot be inferred from other samples, they become Option<serde_json::Value>, which always compiles.

What if two keys produce the same struct name?

Generated struct names are kept unique: when a path has already been used, a numeric suffix (Address2) is added so the output is always valid Rust.

About this tool

JSON to Rust Struct Generator converts a JSON document into idiomatic Rust struct definitions. Objects become their own structs, arrays become Vecs, null becomes Option, and nested objects are generated as separate types with path-based names (e.g. address becomes Address, company.address becomes CompanyAddress).

How to use: paste some JSON, optionally pick a root struct name and whether to emit Serialize/Deserialize derives, then press Run. A copy-ready Rust snippet is returned, including the Cargo dependencies you need.

  • Type inference for numbers, strings, booleans, null and arrays
  • Array samples of the same object are merged — missing fields become Option
  • Rust keywords use raw identifiers (r#type) and serde rename keeps the original JSON keys
  • Non-object roots become newtype structs

Related tools