Omnikit
DevFilesMoneyAll tools
Ctrl K
Dev toolsFile toolsMoney calculatorsAll tools
HomeDeveloper toolsJSON to Rust Struct Converter
EnglishالعربيةবাংলাDeutschEspañolFrançaisPolskiPortuguêsРусский

JSON to Rust Struct Converter

dev

Turn a JSON sample into Rust structs with serde derives, renames, Option and Vec

Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.

Paste a JSON sample and get Rust structs with serde's Serialize and Deserialize derives. Whole numbers become i64 and any decimal makes a field f64; a value that is null or missing from some objects becomes Option<T>, and keys spelt differently from their snake_case field get a serde rename, 1 rename_all when all are camelCase.

Next:
  • JSON to TypeScript Generate TypeScript interfaces or types from a JSON sample
  • JSON Formatter & Validator Format, validate, minify and sort JSON with exact error positions

How to convert JSON to a Rust struct

1

Paste a JSON sample, such as an API response, into the left box.

2

The Rust structs appear as you type, each with #[derive(Serialize, Deserialize)], snake_case fields and the serde renames they need.

3

Turn on Option for every field or PartialEq if you want them, and set the root struct name.

4

Press Copy, or Download to save models.rs, and add serde (with the derive feature) and serde_json to Cargo.toml.

About JSON to Rust Struct Converter

Rust decodes JSON with serde, and every object needs a struct whose fields have the right types and whose names map back to the JSON keys. This converter writes those structs from a sample, so a long API response becomes compiling Rust in one paste.

How types are chosen.

JSON value Rust type
"text" String
true / false bool
42 (whole numbers only) i64
4.5 (any decimal seen) f64
null, and also a type Option
only null, or mixed kinds serde_json::Value
[ ... ] Vec<...>
{ } empty Map<String, Value>
{ ... } a struct of its own

Missing keys. All the objects of an array are merged into one struct. A key that some of them leave out becomes an Option, because serde treats a missing Option as None and every other missing field as an error. Those fields also get skip_serializing_if, so writing the struct back out leaves them out again.

Names. Fields are snake_case. When every key is simply the camelCase form of its field, the struct carries one rename_all; otherwise each differing field gets its own rename. Keywords become raw identifiers such as r#type; self, super and crate cannot be raw, so they become self_ with a rename.

Options. Option on every field suits APIs that may drop any key. Derive PartialEq lets tests compare values. The root struct is called Root unless you name it.

Every output was checked by reading the Rust back with serde's rules and decoding 9 samples with it. Nothing you paste leaves the browser.

Frequently asked questions

How do I convert JSON to a Rust struct?

Paste a JSON sample into the converter and the Rust structs appear beside it, each deriving Serialize and Deserialize. Add serde with the derive feature and serde_json to Cargo.toml, paste the structs into a module, and decode with serde_json::from_str::<Root>(&text).

When does a field become Option<T>?

A field becomes Option when the sample shows it as null, or when some objects of an array leave the key out. Serde decodes a missing key into an Option as None, while any other missing field is an error, so Option is what lets the struct accept every object in the sample.

How are camelCase JSON keys mapped to snake_case fields?

Fields are written in snake_case, as Rust style asks. When every key is the camelCase form of its field, the struct gets one #[serde(rename_all = "camelCase")]; otherwise each field spelled differently gets its own #[serde(rename = "key")], so keys like first-name or 2fa still decode.

Why i64 and f64 rather than i32 or f32?

JSON does not say how large a number may get, so i64 is the safe whole-number type and f64 matches the double precision JSON numbers are read with. A field becomes f64 as soon as any sample value has a decimal part, because serde refuses to read 4.5 into an integer.

What happens to a key named type or match?

Keywords are written as raw identifiers, such as r#type, and serde removes the r# when it matches the key, so no rename is needed. The four keywords that cannot be raw, self, Self, super and crate, become self_ and similar, with a rename back to the original key.

Is my JSON uploaded?

No. The conversion runs in your browser with no request to any server, and the JSON is not stored, so API responses holding tokens or personal data stay on your device. Close the tab and nothing remains.

Sources

  • serde, field attributesrename and skip_serializing_if on a field
  • serde, container attributesrename_all = "camelCase" on a struct
  • The Rust Reference, keywords and raw identifiersWhich names need r#, and the four that cannot be raw
  • Rust API Guidelines, namingUpperCamelCase types, snake_case fields

Last verified 16 October 2026.

Rates and rules change; check the source before you rely on a figure.

Still stuck? Ask about JSON to Rust Struct Converter and anybody who knows can answer. No account needed.

Common uses

  • JSON to Serde StructPaste an API response and get serde structs ready for serde_json::from_str

Same job, other tools: TSV to JSON – Convert tab-separated values, such as a paste from Excel, into JSON · JSON to YAML – Turn JSON into clean, readable YAML for configs · Query String Parser – Split a URL query string into a table of decoded parameters.

Related tools

All developer tools
Base64 Encode & DecodeText and files to Base64 and back, with URL-safe mode and image previewUnix Timestamp ConverterUnix timestamps to dates and dates to timestamps, in any time zoneJSON to TypeScriptGenerate TypeScript interfaces or types from a JSON sampleCSV to JSONConvert CSV to JSON and JSON to CSV, with a table previewYAML to JSONConvert YAML to JSON and JSON to YAML, with anchors resolvedURL Encoder / DecoderPercent-encode or decode text and URLs, and see every part of a linkColor ConverterHEX, RGB, HSL, HWB, OKLCH and CMYK in both directions, with a contrast checkNumber Base ConverterBinary, octal, decimal, hex and any base to 36, exact at any size, with two's complement
Was this tool helpful?
Omnikit

Small jobs, done in your browser. Free, fast and private. Files are never uploaded.

Files

  • Compress Image
  • Image to PDF
  • Merge PDF
  • Compress PDF
  • PDF to Word
  • Word to PDF

Dev

  • JSON Formatter & Validator
  • Base64 Encode & Decode
  • JWT Decoder, Verifier & Encoder
  • Password Generator
  • UUID Generator
  • Unix Timestamp Converter

Money

  • SIP Calculator
  • EMI Calculator
  • GST Calculator
  • FD Calculator
  • PPF Calculator
  • Lumpsum Calculator
EnglishالعربيةবাংলাDeutschEspañolFrançaisPolskiPortuguêsРусский
GuidesQuestionsAboutHow we checkLaw library (beta)PrivacyTermsDisclosureContactMore: Exam practice (UGC NET Paper 1)Runs in your browser. Nothing is uploaded. © 2026 Omnikit (theomnikit.com)