JSON to Rust Struct

Generate Rust struct definitions from JSON, with serde attributes and Option<T> support.

Input data is processed in your browser
Data is never sent to a server

Tool

0 chars

or drag & drop a file

What is JSON to Rust Struct?

This tool converts JSON data into Rust struct definitions.

Hand-writing structs to receive JSON responses in API integrations or WebAssembly development can be tedious, but with this tool you can paste in JSON and automatically generate serde-ready structs.

Key features

  • Automatic addition of serde attributes (#[derive(Serialize, Deserialize)], #[serde(rename)])
  • Automatic conversion to snake_case while preserving original JSON key names
  • Automatic separation of nested structs
  • Automatic escaping of Rust reserved words (raw identifier support)
  • No installation required — runs entirely in the browser

How to Use

  1. Paste your JSON text into the input field.
  2. Optionally specify a name for the root struct.
  3. Enable "Add serde attributes" to automatically add #[derive(Serialize, Deserialize)] and #[serde(rename = "...")] for field names.
  4. Enable "null as Option<T>" to make fields containing null values Option<T> types.
  5. Enable "pub fields" to add the pub modifier to every field.
  6. Click "Convert", or if auto-convert is enabled, the result appears instantly.

FAQ

What are serde attributes?

serde is the most widely used serialization/deserialization library in Rust. When a JSON key name differs from Rust's naming convention (snake_case), the

What happens with nested objects?

Nested objects are automatically generated as separate structs and referenced from the parent struct.

What happens to field names that collide with Rust keywords?

Key names that collide with Rust reserved words such as "type" or "match" are automatically converted to raw identifiers (e.g. r#type).

How are numeric types determined?

Values containing a decimal point are treated as f64, and integers as i64. If you need a more precise type (such as u32), please adjust it manually.

Is my data sent to a server?

No. All conversion happens entirely in your browser.