JSON to Rust Converter
Convert JSON to Rust structs with serde derive macros online. Generates snake_case fields, serde rename attributes, Vec<T> and Option<T> types.
What is the JSON to Rust Converter?
The ByteTools JSON to Rust Converter generates serde-ready structs from a sample JSON document. Every struct derives Serialize and Deserialize, fields are renamed to idiomatic snake_case with #[serde(rename)] attributes preserving the original keys, arrays become Vec<T>, and null or missing values become Option<T>.
- #[derive(Serialize, Deserialize)] on every struct
- snake_case fields with #[serde(rename)] for the original keys
- Option<T> for null values and keys missing from some elements
- Vec<T> arrays and nested structs named from their keys
- Rust keywords handled with raw identifiers like r#type
- 100% private — JSON never leaves your browser
How to use the JSON to Rust Converter
- 1
Paste a JSON sample into the input box.
- 2
Set the root struct name and choose whether to derive Debug.
- 3
Click Generate Rust to build the serde structs.
- 4
Copy the code or download it as a .rs file.
About the JSON to Rust Converter
The ByteTools JSON to Rust Converter generates serde-ready structs from a sample JSON document. Every struct derives Serialize and Deserialize, fields are renamed to idiomatic snake_case with #[serde(rename)] attributes preserving the original keys, arrays become Vec<T>, and null or missing values become Option<T>.
It is aimed at Rust developers consuming JSON APIs with serde_json or reqwest. Nested objects become their own structs named from their keys, arrays of objects are merged into one shape with optional fields, camelCase keys are converted automatically, and reserved words like type become raw identifiers such as r#type so the code compiles as-is.
The generator runs 100% locally in your browser. Your JSON never leaves the page — nothing is uploaded or stored — so it is safe for internal API payloads and private data models.
Frequently asked questions
How do I convert JSON to Rust structs?
Paste a JSON sample, set the root struct name and click Generate Rust. The tool infers the field types, emits one struct per object shape and adds the serde derives, so you can deserialize with serde_json::from_str::<Root>(&json) right away.
When is #[serde(rename)] added?
Whenever the idiomatic snake_case field name differs from the original JSON key — for example userName becoming user_name. Keys that are already snake_case need no attribute, keeping the output clean.
How are optional and null fields typed?
They become Option<T>. serde's derive treats Option fields as optional during deserialization, so a missing key simply becomes None instead of an error.
What types are used for numbers?
Whole numbers become i64 and anything with a decimal point becomes f64. These are the safest defaults for JSON; narrow them to i32 or u32 by hand if you know the value range.
What happens with mixed-type fields?
A field whose sample values have different types falls back to serde_json::Value, and a comment notes that the serde_json crate is required. That keeps deserialization working for irregular data.
Is my JSON uploaded anywhere?
No. Everything runs in your browser tab with JavaScript — private payloads are never transmitted or stored.
Related tools
JSON to Go Struct
Convert JSON to Go structs online with exported fields and json tags. Generates nested structs and slice types from a sample — free and 100% in-browser.
JSON to TypeScript
Generate TypeScript interfaces from a JSON sample online. Infers types recursively, merges array shapes and marks optional keys — 100% in your browser.
JSON to C# Converter
Convert JSON to C# classes or records online. Infers types from a sample, adds JsonPropertyName attributes and nullable types — all in your browser.
JSON Formatter
Format, beautify and minify JSON online with 2-space, 4-space or tab indentation. Sort keys alphabetically and catch syntax errors instantly — free and private.
JSON Validator
Free online JSON validator: validate JSON and find syntax errors with the exact line and column. See root type, key counts and depth — instant and 100% private.