RealJSON
Try now

JSON to Rust Struct (serde) Converter

Paste any JSON and get Rust structs instantly — nested types, arrays and optional fields included.

Root type name

JSON input

Rust structs

 

In short: A JSON to Rust converter generates struct definitions with serde Serialize and Deserialize derives from a JSON document. Nested objects become their own structs, arrays become Vec<T> and nullable or missing fields become Option<T>.

JSON to Rust Converter

Writing Rust structs by hand for every API response is slow and easy to get wrong. This tool infers the types from real data: it merges every item of an array, so a field that is missing from some items is marked optional instead of being silently dropped.

Add serde (with the derive feature) and serde_json, then call serde_json::from_str::<Root>(&text). Everything runs locally in your browser — safe for private payloads.

How the Conversion Works

Type mapping

strings → String, integers → i64, decimals → f64, booleans → bool, arrays → Vec<T> and unknown values → serde_json::Value.

Null and optional fields

Missing or null fields become Option<T>; optional keys also get #[serde(default, skip_serializing_if = "Option::is_none")].

Naming

Keys become snake_case field names with #[serde(rename = "…")] to preserve the original key; Rust keywords are emitted as raw identifiers (r#type).

Frequently Asked Questions

How do I convert JSON to Rust?

Paste your JSON, set a root type name, and Rust structs are generated instantly. Copy the result or download it as a .rs file.

How are nested objects and arrays converted to Rust?

Each nested object becomes its own named type and arrays use the element type inferred from all of their items, so arrays of objects are fully typed.

How are null and missing values handled?

Missing or null fields become Option<T>; optional keys also get #[serde(default, skip_serializing_if = "Option::is_none")].

What do I need in Cargo.toml?

Add serde = { version = "1", features = ["derive"] } and serde_json = "1". The generated structs derive Debug, Clone, Serialize and Deserialize.

Is my JSON sent to a server to generate the Rust structs?

No. Generation runs entirely in your browser — your JSON never leaves your device.

Related Tools

JSON to TypeScript · JSON to JSON Schema · JSON Validator · JSON Formatter

Browse all free JSON tools →

Related tools