DocumentsImagesMediaPDF Tools

JSON to Rust Struct

Generate Rust structs with serde from JSON, free, in your browser.

Processed in your browser

From JSON to Rust Struct with serde

Compatible with the serde ecosystem

Generates structs ready to use with serde_json, reqwest, Actix-web, Axum, and any Rust ecosystem crate.

100% private

Your JSON never leaves your browser. No signup, no telemetry, no server uploads.

Correct Rust conventions

Automatic snake_case, Option<T> for nullables, correct numeric types (i64, f64). Idiomatic code.

Instant

Structs generated in real time. No buttons, no waiting, no limits.

Three steps, no hassle

1

Paste your JSON

Paste the JSON you want to model. Can be a nested object, an array, or any valid JSON structure.

2

Instant generation

The tool generates Rust structs with serde derivations automatically, following snake_case conventions.

3

Copy the code

Copy the generated code and add the serde dependency to your Cargo.toml to use it directly.

Got questions?

serde (serialization/deserialization) is the most popular serialization framework in the Rust ecosystem. It converts Rust structs to and from formats like JSON, YAML, TOML, MessagePack, CBOR, and many more. The key to serde is that it uses compile-time macros, meaning zero runtime overhead: the generated code is as efficient as if you had written the serialization manually.

The #[derive(Serialize, Deserialize)] macro in Rust instructs the compiler to automatically generate the implementation of serde's Serialize and Deserialize traits for the struct. This eliminates the need to write serialization code manually. It is equivalent to implementing an interface, but the code is generated at compile time via procedural macros.

snake_case is Rust's official naming convention for variables, struct fields, and functions (defined in the Rust API Guidelines). However, REST APIs often return JSON in camelCase. serde handles this mismatch automatically with the #[serde(rename_all = "camelCase")] attribute at the struct level, or #[serde(rename = "fieldName")] per individual field.

In Rust there is no null — instead the Option<T> type is used, which can be Some(value) or None. When a JSON field can be null or absent, the corresponding Rust type is Option<T>, for example Option<String> or Option<i64>. serde automatically deserializes null as None and skips fields with None when serializing (with #[serde(skip_serializing_if = "Option::is_none")]).

Add these lines to your Cargo.toml: serde = { version = "1.0", features = ["derive"] } and serde_json = "1.0". The "derive" feature enables the #[derive(Serialize, Deserialize)] macros. serde_json provides serde_json::from_str() for deserialization and serde_json::to_string() for serialization. These are among the most downloaded crates in the Rust ecosystem.

Rust as Stack Overflow's most loved language, the serde ecosystem, and WebAssembly with Rust

Rust has been voted the most loved programming language in the Stack Overflow Developer Survey for 9 consecutive years (2016–2024). This popularity stems from its unique proposition: memory safety without a garbage collector, performance comparable to C/C++, and a type system that prevents entire classes of bugs at compile time — null pointer dereferences, data races, and buffer overflows. More and more projects in critical systems, CLIs, and high-performance services are migrating to Rust.

serde is the pillar of serialization in Rust. With over 300 million downloads on crates.io, it is one of the most ubiquitous dependencies in the ecosystem. What makes serde special is its format-agnostic data model architecture: structs implement against serde's abstract data model once, and formats (JSON, YAML, TOML, Bincode, MessagePack, etc.) implement their own adapter. This means switching from JSON to MSGPACK in a Rust project is often as simple as changing one crate.

WebAssembly (Wasm) is another area where Rust excels. With wasm-bindgen and wasm-pack, you can compile Rust code to WebAssembly and run it in the browser at near-native performance. serde_json works on Wasm targets without changes. Projects like Figma (its rendering engine), Cloudflare Workers, and parts of Firefox are written in Rust. The tool on convertir.ai uses similar technology: client-side processing without sending data to a server.