JSON to Rust Serde Struct Generator
Paste a JSON sample and get ready-to-use Rust structs annotated with serde Serialize and Deserialize. Nested objects become their own structs, arrays become Vec<T>, and non snake_case keys get a serde rename so deserialization round-trips cleanly.
How to convert JSON to Rust serde structs
- Paste a JSON object into the input box.
- Optionally rename the root struct (defaults to Root).
- Copy the generated structs or download them as a .rs file.
Examples
Flat object
{"name":"Ada","age":36}use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct Root {
name: String,
age: i64,
}camelCase key with serde rename
{"firstName":"Ada"}#[derive(Serialize, Deserialize)]
struct Root {
#[serde(rename = "firstName")]
first_name: String,
}Frequently asked questions
What does this tool do?
It reads a JSON sample and generates matching Rust structs, each annotated with #[derive(Serialize, Deserialize)] so you can serialize and deserialize the data with serde and serde_json.
How are JSON types mapped to Rust?
Strings become String, booleans become bool, whole numbers become i64 and fractional numbers become f64. A null becomes Option<serde_json::Value>, arrays become Vec<T>, and each nested object becomes its own struct.
Why do some fields have a #[serde(rename = ...)] attribute?
Rust fields use snake_case, so a JSON key like firstName is renamed to first_name and given #[serde(rename = "firstName")]. The rename keeps the original JSON key intact when you serialize or deserialize.
Does it handle integers versus floats correctly?
JSON has a single number type, so the generator looks at the sample value. An integer like 36 maps to i64 and a value with a decimal like 1.5 maps to f64. Widen the type by hand if a field can be either.
Is my JSON sent to a server?
No. Parsing and code generation run entirely in your browser, so your data never leaves your machine.
Why did I get an error instead of structs?
The tool needs valid JSON with an object at the top level. Invalid syntax or a top-level array, string or number returns an error message instead of Rust code.
Related tools
JSON to TypeScript
Generate TypeScript interfaces from a JSON sample. Infers nested objects, arrays and union types, then copy or download the .ts file. Runs in your browser.
JSON Formatter
Format, validate and minify JSON online. Pretty-print with custom indentation, sort keys and catch syntax errors. Runs in your browser.
CSV to JSON
Convert CSV to JSON online. Turn spreadsheet rows into clean JSON objects or arrays, with smart number and boolean typing. Free tier plus API.
.env to JSON
Convert a .env file to JSON, or JSON back to .env. Parses KEY=value lines, comments, quotes and export. Runs entirely in your browser.
Aspect Ratio Calculator
Calculate aspect ratios fast. Enter a ratio like 16:9 and one dimension to get the other, or enter width and height to simplify the ratio.
Base58 Encoder
Encode and decode Base58 online with the Bitcoin alphabet. Convert text to Base58 or back, UTF-8 safe, no confusing 0 O I l. Runs in your browser.