HCODX/JSON to Rust Struct
100% browser-based · Nested types · Rust-idiomatic naming

JSON to Rust struct

Paste JSON and get a Rust struct with #[derive(Serialize, Deserialize)], snake_case field names with #[serde(rename)] when needed, and nested types.

JSON input
Rust output
Generator options
Input size
0 B
Output size
0 B
Output lines
0
Status
Ready
Example

JSON in, Rust struct out

Paste a typical JSON payload and the tool emits idiomatic Rust types — nested objects each become their own type.

JSON
{
  "id": 1,
  "name": "Alice",
  "isActive": true
}
Rust
Generated Rust appears here.
Use cases

What you'll use this for

Skip the boilerplate. Whenever you have an example JSON payload and need typed code on the other side, paste and generate.

API client models

Generate DTOs for a third-party REST API from a sample response.

Database row types

Model JSON columns or document-store records as native Rust types.

Mobile + backend parity

Keep client and server types in sync — both generated from the same JSON.

Fixtures and tests

Turn fixture JSON into typed code for unit tests and integration mocks.

Step by step

How to convert JSON to Rust

1

Paste your JSON

Drop a valid JSON object into the left editor. Arrays at the root work too — the first element is sampled.

2

Pick a class name

Default is Root. Use anything PascalCase that fits your domain.

3

Click Generate

Or leave auto-generate on for live updates as you edit JSON. Runs entirely in your browser.

4

Copy or download

Copy to clipboard or save as a .rs file ready to drop into your project.

FAQ

Frequently asked questions

Yes. Each struct derives Serialize and Deserialize from serde, ready for serde_json.

They are converted to snake_case and annotated with #[serde(rename = "originalName")] to preserve wire-format compatibility.

Yes. Each nested JSON object becomes its own struct with PascalCase naming.

Yes. Completely free, no signup, no limits. Runs entirely in your browser.

About

About JSON to Rust struct

This tool converts a sample JSON payload into idiomatic Rust code. Every nested object is recursively turned into its own type with PascalCase naming, while keys are converted to the conventional case for the language.

Type inference

  • Strings stay strings.
  • Integers use the language's widest safe integer type (e.g. long, Int, i64).
  • Decimals become double-precision floats.
  • Arrays become a generic list keyed off the first element's type.
  • Booleans map to the native boolean type.
  • Nested objects recurse into their own type definitions.

Privacy

  • All conversion happens locally in your browser.
  • No JSON ever leaves your device.
  • No signup, no tracking of payloads.
Related

Related tools