ToolZoneX
Blog

JSON to Rust Serde Struct Converter

Paste a JSON sample to instantly generate matching Rust structs annotated with #[derive(Serialize, Deserialize)] and serde rename attributes. Free online developer tool.

Paste JSON
Rust Structs (serde)
Rust struct definitions will appear here...

Free JSON to Rust Serde Struct Converter

Paste a JSON sample to instantly generate matching Rust structs annotated with#[derive(Serialize, Deserialize)], snake_case field names, and#[serde(rename = "...")] attributes that preserve your original JSON keys.

How to Use It

Paste any JSON object or array, or click "Load Example." The tool infers a type shape and emits one pub struct per object level, converting field names to idiomatic snake_case and adding a #[serde(rename = "...")] attribute whenever that differs from the original key. Arrays become Vec<T>, and any field that's optional or nullable in your sample is wrapped in Option<T>.

Example

Given {"name": "Ann", "age": 30, "tags": ["a","b"], "address": {"city": "NYC", "zip": null}}, the tool emits a RootAddress struct with pub city: String andpub zip: Option<serde_json::Value>, plus a Root struct referencing it with pub tags: Vec<String>.

Common Use Cases

  • Generating serde-compatible structs to deserialize an API response in a Rust service.
  • Bootstrapping request/response types for an Actix-web or Axum handler.
  • Keeping Rust field names idiomatic (snake_case) while preserving exact JSON compatibility via rename attributes.

FAQs

Why does the output need the serde crate?

The generated structs rely on serde::{Serialize, Deserialize} for the derive macros and, for unknown/mixed-type fields, on serde_json::Value to hold arbitrary JSON — addserde (with the derive feature) and serde_json to yourCargo.toml.

When does a field get a #[serde(rename)] attribute?

Only when converting the original key to snake_case actually changes it — for example, a JSON keyuserId becomes the Rust field user_id with#[serde(rename = "userId")] so serialization still round-trips to the exact original key.

Is my JSON uploaded anywhere?

No — parsing and struct generation happen entirely client-side in your browser. Nothing you paste is sent to a server.