Boneyard Tools

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

  1. Paste a JSON object into the input box.
  2. Optionally rename the root struct (defaults to Root).
  3. 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