Paste valid JSON (up to 200,000 characters).
Review inferred structs and Serde annotations.
Paste valid JSON (up to 200,000 characters).
Review inferred structs and Serde annotations.
JSON to Rust guide
Paste a valid JSON sample and generate Rust struct declarations with Serialize and Deserialize derives. Nested objects become named types; fields retain their original JSON keys through Serde rename attributes. This tool runs locally, so your payload never needs to leave the browser. This tool is free to use. No account or payment is required.
Last updated
JSON objects become Rust structs with Serialize and Deserialize derives. Property names such as full-name, type, or URLs are normalized to Rust identifiers while serde(rename) preserves the original JSON key during serialization and deserialization.
Nested objects receive unique type names and arrays generate Vec<T> where sample values identify a stable element type. Null mixed with a single observed type becomes Option<T>.
Mixed scalar array elements and null-only values use serde_json::Value instead of guessing an incorrect Rust union. Empty arrays also use Value because no element type has been observed.
A single JSON sample cannot establish whether a field is optional in other responses, whether number ranges fit your domain, or whether unseen API variants exist. Numeric precision and very large/deep input are guarded rather than silently altered.
Use Rust structs for typed application code and Serde deserialization. Use JSON Schema when you need a language-neutral contract shared with clients that do not use Rust.
If different records in one JSON array have different sets of keys, the generator may mark fields as Option<T>; confirm those differences against actual API documentation.
Preserve a hyphenated field name with a Serde rename attribute.
{"id":1,"full-name":"Ada"}use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
#[serde(rename = "id")]
pub id: i64,
#[serde(rename = "full-name")]
pub full_name: String,
}Common questions
No. It parses the JSON and emits text locally in the browser. The generated Rust code is never executed here.
Add serde with the derive feature and serde_json to your Cargo dependencies. Review the generated model before integrating it into production code.
A null-only field has an unknown non-null type and uses serde_json::Value. Null alongside one known type becomes Option<T>. Other mixed types use Value with a warning.
Not reliably. Fields present in a single object are treated as required unless observed object array variants omit them. Confirm real response variants manually.
Yes. Serde rename attributes preserve exact JSON keys even when Rust identifiers must be normalized or disambiguated.
Debugging a specific JSON issue? Browse JSON troubleshooting.