Developer Tools
JSON to Rust Struct Converter
Paste JSON and get idiomatic Rust structs with serde derives, snake_case fields, Option<T> for nulls, and Vec<T> for arrays. Runs in your browser.
Output options
Live preview updates with every change. All inference happens in your browser; the JSON you paste is not uploaded.
Used for the root struct. Sanitized to a valid Rust PascalCase identifier.
Integer type
JSON numbers without a fractional part. i64 is the safe default for IDs and timestamps. Floats always map to f64.
Serde rename_all
Emit per-field #[serde(rename)] only when the JSON key cannot be a Rust field.
Derives
Standard serde derives. Debug is on by default so the structs print cleanly in test failures and logs.
Rust type mapping
- JSON string becomes String for owned data. Use &str manually if you do not need to own the value.
- JSON number with no fractional part becomes the integer type you chose, and a number with a fractional part becomes f64. If any sample has a decimal value, the whole field is f64.
- JSON bool becomes bool. JSON null becomes Option<T> when combined with another type, or serde_json::Value when seen alone.
- JSON array becomes Vec<T>. Empty arrays become Vec<serde_json::Value> until you provide a sample with a real element.
- JSON object becomes a named pub struct. Nested objects are extracted into their own structs and referenced by name, the same way a Rustacean would write the code by hand.
What serde does with these structs
- Paste a JSON sample, copy the generated Rust, and call serde_json::from_str to deserialize, or serde_json::to_string to serialize.
- The #[serde(rename_all)] attribute lets one rule cover every field whose JSON wire name differs from the Rust field name. Per-field renames are emitted only when one rule is not enough.
- Option<T> fields default to None when the JSON key is missing. Combine with #[serde(default)] if your input also omits required fields.
- For very large schemas, generated structs are a strong starting point; you can replace serde_json::Value markers with concrete enums once you know the union members.
- Generation runs entirely in your browser. The JSON you paste is never sent to a server.
How to use
- Paste a JSON sample into the input. Use Load sample JSON for a tour of the formatting rules.
- Pick the integer type (i64 is the safe default for IDs) and a serde rename_all rule that matches your wire format, if any.
- Toggle derives (Serialize, Deserialize, Debug, Clone, PartialEq) and decide whether structs and fields are pub.
- Use Option<T> for missing or null so absence stays explicit. Keep serde_json::Value for unknown fields, or switch it off for stricter types.
- Copy the Rust output, paste into your project, and call serde_json::from_str or to_string to deserialize and serialize.
About this tool
JSON to Rust Struct Converter parses a JSON sample with the browser's native JSON.parse, walks the value tree, and emits idiomatic Rust struct declarations ready for serde. Every unique object shape becomes its own named pub struct with snake_case fields; nested objects are pulled into their own structs and referenced by name so the file reads top-down the way a Rustacean would write it. Field names follow Rust style and use a raw identifier (r#type) or a trailing underscore for reserved words that cannot be raw (self, crate, Self). When the original JSON key cannot be expressed as a Rust field without changing the wire format (camelCase, kebab-case, leading digits), a per-field #[serde(rename = "...")] attribute preserves the key exactly. A struct-level #[serde(rename_all = "...")] toggle covers entire structs at once, with options for camelCase, snake_case, PascalCase, kebab-case, and SCREAMING_SNAKE_CASE. Numeric inference picks i64 by default for integers (configurable to i8, i16, i32, u8, u16, u32, or u64) and f64 for floats; any sample with a fractional value promotes the whole field to f64. Optional and nullable handling is structural: a key that is missing in some object samples or set to JSON null in any sample is wrapped in Option<T>. Arrays become Vec<T> with the element schema merged across every element; empty arrays and heterogeneous unions fall back to serde_json::Value with an explanation. Configurable serde derives let you add Serialize, Deserialize, Debug, Clone, and PartialEq with one click. Useful for Rust developers integrating a third-party API by pasting a sample response, porting a JSON config to a typed struct, prototyping a CLI tool, or generating a quick scaffold for an axum / actix-web handler. Everything runs locally in your browser; the JSON you paste is never uploaded.
Free to use. Works in your browser. No signup, no login.
Related tools
You may also like
JSON to TypeScript Converter
Generate TypeScript interfaces or types from any JSON value with full inference.
Open tool
DeveloperJSON to Go Struct Converter
Generate idiomatic Go structs with json tags from any JSON value.
Open tool
DeveloperJSON to Python Converter
Generate a Python dict, dataclasses, or Pydantic models from any JSON value.
Open tool
DeveloperJSON to Java Class Converter
Generate Java POJOs, records, or Lombok types (Jackson or Gson) from any JSON.
Open tool
DeveloperJSON to C# Class Converter
Generate C# classes or records (System.Text.Json or Newtonsoft) from any JSON.
Open tool
DeveloperJSON Formatter
Format, minify, and validate JSON in your browser.
Open tool