Toolvore

JSON to Rust

Generate Rust Serde structs from JSON, preserve supported large integer types and review explicit optional, mixed-type and f64 assumptions.

This tool processes its input contents in your browser instead of sending them to a processing service. Page, asset and fixed usage-measurement requests are described on the Privacy page.

Generate Rust Serde structs from JSON, preserve supported large integer types and review explicit optional, mixed-type and f64 assumptions.

How to use it

  1. 1Paste or open a supported local source file, or load the example.
  2. 2Review settings and run the explicit generation or inspection action.
  3. 3Inspect the complete result and download it with its count report.

Example

Input
{"orderId":9007199254740993,"type":"sale"}
Output
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[serde(deny_unknown_fields)] pub struct Root { #[serde(rename = "orderId")] pub order_id: i64, #[serde(rename = "type")] pub type_value: std::string::String, }

The integer is classified directly from its exact token into the signed 64-bit range. Field renaming preserves orderId and the Rust keyword type without placing them directly into Rust identifiers.

What happens to your data

Rust type generation reads the JSON locally in tab memory. No source file is uploaded or retained as account history. Optional outcome counts omit JSON keys and numeric tokens.

Last updated November 2026

Generate Rust Serde data types from a JSON sample without uploading it. Review readable struct definitions, source-key renaming, integer choices and the places where a sample cannot establish a precise type before adding the result to your project.

How it works

Inference reads exact JSON number tokens instead of converting every value through JavaScript Number. An observed integer shape becomes i64 when all examples fit the signed 64-bit range. If all are nonnegative and require the unsigned range, it becomes u64. A mixed set that cannot fit either consistent range fails before a file is offered. Decimal or exponent spellings select approximate f64, with overflow and nonzero underflow rejected. Quote numbers whose exact representation lies outside those supported ranges.

Objects become named structs deriving Debug, Clone, Serialize and Deserialize. A serde rename attribute preserves each original JSON key. Rust field names use ASCII snake case, safe prefixes and distinct suffixes where normalization would collide. Reserved words receive a safe field identifier while the rename keeps the JSON spelling. Nested structs receive distinct generated names. The generated file expects serde with its derive feature and serde_json in your own Cargo project.

Arrays infer one item shape from their examples. Compatible object examples merge by key. Fields absent in another observed object become Option. Null samples also become Option, so missing and explicitly null values are intentionally represented together. Empty arrays, null-only shapes and heterogeneous non-null types use serde_json::Value and are counted in the report. That fallback is a review point because a sample supplies insufficient evidence for a single narrower Rust type. The generator does not infer dates, UUIDs, enums or recursive application models from string appearance.

Generated structs carry deny_unknown_fields, which makes unobserved JSON fields an explicit deserialization error. Review that strictness against your API's evolution rules. The tool returns source code for review and compilation in your application. It does not fetch an API, run a Cargo build in the browser or prove that unseen records satisfy the inferred model.

Input is strict UTF-8 JSON up to 128 KiB, 24 nesting levels and 20,000 parser tokens. Repeated decoded keys fail even when their escape spellings differ. Number tokens are limited to 4,096 characters. Each inferred object shape can contain up to 256 distinct fields. Complete generated output is capped at 512 KiB. A failed limit check leaves the source available for revision and offers no partial completed download. The result preview may be shortened, while Copy and Download contain the complete result. Editing the input or settings clears older exports. The root name starts with an uppercase ASCII letter and contains up to 64 letters/digits, excluding Self.

Reading, parsing and generation run in this browser tab. Source text and generated files are held in memory, with no source upload or saved history. Optional workflow measurement records fixed counts and outcomes without JSON keys, link destinations or source values. The separate MCP operation processes explicitly supplied arguments on Toolvore's server under its published smaller limits.

Worked example: Retain a supported exact integer type

Input
{"orderId":9007199254740993,"type":"sale"}
Result
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[serde(deny_unknown_fields)] pub struct Root { #[serde(rename = "orderId")] pub order_id: i64, #[serde(rename = "type")] pub type_value: std::string::String, }

The integer is classified directly from its exact token into the signed 64-bit range. Field renaming preserves orderId and the Rust keyword type without placing them directly into Rust identifiers.

Common use cases

  • Prepare a Serde model for a sample API response.
  • Keep supported large integer identifiers in an exact Rust integer type.
  • Handle keyword, punctuation or camelCase JSON keys through explicit renaming.
  • Spot optional and mixed shapes that deserve a deliberate application model.

Frequently asked questions

Can it retain 9007199254740993?+

Yes. That exact integer token fits i64 and is classified without a JavaScript Number conversion. Larger tokens must fit a consistent signed or unsigned 64-bit shape.

Why did it use serde_json::Value?+

An empty, null-only or heterogeneous shape does not establish one narrow Rust value type. Review the fallback and replace it with your intended contract when you know it.

Are null and missing fields different?+

Both use Option in the generated model. Implement a custom representation when your application must distinguish them.

What must my Cargo project include?+

Use serde with the derive feature and serde_json. Compile the generated file and test representative and future records in your own project.