Omnikit
DevFilesMoneyAll tools
Ctrl K
Dev toolsFile toolsMoney calculatorsAll tools
HomeDeveloper toolsJSON to Rust Struct ConverterJSON to Serde Struct

JSON to Serde Struct

dev

Paste an API response and get serde structs ready for serde_json::from_str

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

Decoding an API response with serde_json needs a struct for every object, with snake_case fields, a rename for each key spelled another way, and Option wherever a value can be null or missing. Paste the response and get those structs with Serialize and Deserialize derived, a single rename_all when the keys are camelCase, and i64 or f64 chosen per field.

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 use JSON to Serde Struct

1

Paste or type your input.

2

Choose the options you need.

3

Press Ctrl+Enter, then copy or download.

How JSON to Serde Struct works

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.

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.

The rest of the article, and all 6 questions about JSON to Rust Struct Converter, are on the JSON to Rust Struct Converter page.

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.

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.

More ways to use JSON to Rust Struct Converter

  • JSON to Rust Struct ConverterTurn a JSON sample into Rust structs with serde derives, renames, Option and Vec

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
GuidesQuestionsAboutHow we checkLaw library (beta)PrivacyTermsDisclosureContactMore: Exam practice (UGC NET Paper 1)Runs in your browser. Nothing is uploaded. © 2026 Omnikit (theomnikit.com)