JSON to Rust Serde Struct Converter Online

Generate Rust structs with `#[derive(Debug, Clone, Serialize, Deserialize)]`, `Option<T>`, `Vec<T>`, and `#[serde(rename)]` attributes directly from JSON.

Also working with Go or TypeScript? Try the JSON to Go Struct Converter →

Loading converter…

Quick answer

To convert JSON to a Rust struct, paste your JSON into the KaviForge JSON to Rust Converter. It generates Rust `pub struct` definitions with Serde derive macros, `snake_case` field names paired with `#[serde(rename = "...")]` when the original key is camelCase, and `Option<T>` for nullable or optional fields.

Deserializing JSON in Rust with `serde` and `serde_json` is fast and memory-safe, but writing boilerplate struct definitions with `#[serde(rename = "...")]` for camelCase JSON APIs takes time.

This converter parses your JSON locally and emits idiomatic Rust structs with `snake_case` fields, `Option<T>` for optional keys, `i64`/`f64` numeric types, and `Vec<T>` for arrays.

How to Convert JSON to Rust Serde Structs

  1. 1Paste a sample JSON object or array into the left editor or upload a `.json` file.
  2. 2Set your root struct name (for example, `ApiResponse`).
  3. 3Review the generated Rust structs and Serde attributes in the right editor.
  4. 4Click "Copy to Clipboard" or download the `.rs` file.

Features

Ready for serde & serde_json

Includes `use serde::{Deserialize, Serialize};` and derive macros on every generated struct.

Automatic #[serde(rename)]

Converts camelCase JSON keys into idiomatic Rust `snake_case` fields with `#[serde(rename = "...")]`.

Option<T> & Vec<T> Inference

Nullable or missing array fields become `Option<T>`, and arrays become `Vec<T>`.

Rust Keyword Escaping

Automatically handles reserved Rust keywords like `type`, `match`, `ref`, or `in` safely.

Download .rs File

Copy to clipboard or save as a `.rs` file.

100% Client-Side

Your JSON stays in your browser tab — nothing is uploaded.

When to Use the JSON to Rust Struct Converter

Build Reqwest & Axum API types

Generate Serde structs for HTTP client responses or Axum/Actix request bodies.

Parse camelCase JSON in Rust

Keep Rust compiler warnings happy with `snake_case` field names mapped to camelCase JSON keys.

How JSON Maps to Rust & Serde

Rust’s `serde_json` crate maps JSON objects to strongly typed structs at compile time. When a field may be `null` or omitted on some objects in an array, wrapping its type in `Option<T>` allows deserialization to succeed without panicking.

Our converter merges array items to spot optional fields, separates `i64` integers from `f64` floats, and extracts nested objects into standalone structs.

JSON to Rust Struct Converter FAQs

Does this generator include Serde attributes?

Yes. Every struct includes `#[derive(Debug, Clone, Serialize, Deserialize)]` and adds `#[serde(rename = "...")]` whenever a JSON key differs from its Rust `snake_case` identifier.

How are null or optional JSON fields represented in Rust?

Fields that are `null` or missing on some array items are wrapped in `Option<T>`. Fields that are only ever `null` in your sample use `Option<serde_json::Value>`.