LazyTools

🔒 Every tool runs in your browser — the files and values you enter are never uploaded to any server. How it works

🦀 JSON to Rust Struct Converter

Paste JSON and get Rust structs deriving Serialize/Deserialize — types, Vec, nested structs and serde renames handled for you.

2 structs generated

Rate this tool:
Anonymous — no account, no identifier

How the json to rust struct converter works

The converter parses your JSON and emits Rust structs that derive serde’s Serialize and Deserialize. Whole numbers become i64, decimals f64, booleans bool, strings String, arrays Vec<...> and nested objects their own struct. Field names are converted to snake_case; when that differs from the JSON key (e.g. userName → user_name) a #[serde(rename = "…")] attribute is added so (de)serialization still matches the original key. Optional fields (absent in some array elements) are wrapped in Option<...>.

This is the boilerplate for deriving typed Rust models from an API in seconds, ready to use with serde_json. Refine as needed: a whole number is typed i64 (use u64/i32 where appropriate), and fields that may be missing are Option<...> — you can also add #[serde(default)] where a sensible default exists. Because parsing is local, nothing about your data leaves the browser.

Frequently asked questions

How do I convert JSON to a Rust struct?

Paste a JSON sample and the tool generates Rust structs deriving Serialize and Deserialize. Copy the output and use it with serde_json to parse the same JSON.

Does it handle camelCase JSON keys?

Yes — field names are converted to Rust’s snake_case convention, and when that differs from the JSON key a #[serde(rename = "originalKey")] attribute is added so deserialization still matches.

What number types does it use?

Whole numbers become i64 and decimals f64. Adjust to u64, i32 or f32 as your data requires — the tool picks safe defaults from the sample.

How are optional or null fields handled?

Fields missing from some elements of an array are wrapped in Option<...>. A JSON null is typed Option<serde_json::Value>; tighten it once you know the real type.

Is my JSON uploaded?

No — generation runs entirely in your browser and works offline, so your data stays on your device.

Related developer tools

From the blog