JSON to Rust Struct Generator
Convert JSON into Rust structs with serde derives, snake_case fields, and Vec/Option types. Handles nesting and arrays. Runs entirely in your browser.
Input JSON
How it works
- Paste a JSON sample and click Generate Rust.
- Each object becomes a
structwith#[derive(Serialize, Deserialize)]; arrays becomeVec<T>. - Fields whose name differs from the JSON key get an explicit
#[serde(rename = "...")]. - Nothing leaves your browser.
Type mapping
| JSON value | Rust type |
|---|---|
42 | i64 |
3.14 | f64 |
"hi" | String |
true | bool |
null | serde_json::Value |
[{...}] | Vec<Nested> |
About JSON to Rust
rust-serde models are usually written by reading a JSON sample and transcribing it by hand, which is tedious for nested payloads. This generator walks the sample and emits structs you can drop into a module, complete with the derives and rename attributes serde needs.
As with any sample-driven generator, inference reflects only what the sample shows. A null becomes Value, a heterogeneous array becomes Vec<Value>, and a missing field is simply absent. Refine optional fields to Option<T> once you know the real schema.
Type inference
JSON integers become `i64` and fractional numbers become `f64`; booleans become `bool` and strings become `String`. A JSON array becomes `Vec<T>`, where `T` is the merged element type — objects are folded into one struct and primitives are collapsed to their common type.
A null value becomes `serde_json::Value`. This is deliberately honest: Rust has no JSON `null` type, and a single `null` in the sample gives no information about what the field should be when present, so `Value` is the safe placeholder you then specialise.
Naming and rename attributes
Field names are snake_cased from the JSON key. When the key is not already snake_case — `userName`, `created-at` — the field is renamed to a valid Rust identifier and an explicit `#[serde(rename = "originalKey")]` is emitted so the wire format is preserved.
Struct names come from the key that held the object, capitalised. Collisions across keys that capitalise alike get a numeric suffix rather than two structs with the same identifier.
What you get
The output is a set of `struct` definitions plus the `use` lines serde needs. It is a starting point for a typed model, not a validation layer; you would add `#[serde(default)]`, `Option<T>` for genuinely optional fields, and custom `Deserialize` impls where the schema is loose.
All conversion happens in your browser. The JSON is parsed and walked by JavaScript, nothing is transmitted, and there is no server in the path.
Frequently Asked Questions
Are the structs ready to deserialise with serde?
How are null and missing fields handled?
Is my data sent to a server?
Do I need an account or API key?
Can I use these tools offline?
All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.