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

Type mapping

JSON valueRust type
42i64
3.14f64
"hi"String
truebool
nullserde_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?
Yes. Every struct carries `#[derive(Debug, Clone, Serialize, Deserialize)]`, and a field whose name differs from its JSON key gets an explicit `#[serde(rename = "key")]`. Numbers are `i64`/`f64` and text is `String`, so the structs bind directly with serde_json.
How are null and missing fields handled?
A null in the sample becomes `serde_json::Value`, since Rust has no single JSON `null` type. For optional fields you would normally want `Option<T>`, but the generator cannot know the non-null type from a null alone, so it emits `Value` and you refine it. Fields absent from the sample are absent from the struct.
Is my data sent to a server?
No. Every tool on jsonversal runs entirely in your browser using the Web Crypto API, File API, and Clipboard API. Nothing is ever uploaded — not even the JSON you paste in.
Do I need an account or API key?
No signup, no email, no API key. All tools are free to use with no signup required.
Can I use these tools offline?
Yes. Once the page loads, all tools work offline. There are no external API calls or CDN dependencies at runtime.
🔒
Your data never leaves your device

All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.

esc
↑↓ navigate ↵ open esc close