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.
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
- 1Paste a sample JSON object or array into the left editor or upload a `.json` file.
- 2Set your root struct name (for example, `ApiResponse`).
- 3Review the generated Rust structs and Serde attributes in the right editor.
- 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>`.
Related Developer Tools
JSON to Go Struct Converter
Convert JSON into Go struct definitions with json struct tags, omitempty pointers, and int64/float64 inference.
JSON to TypeScript Converter
Generate exportable TypeScript interfaces from any JSON object or array, with nested types and optional fields.
JSON to Python Pydantic Converter
Generate Python Pydantic BaseModel classes or @dataclass definitions from JSON with Optional and List type hints.
JSON Formatter & Validator
Pretty print, beautify, minify, and validate JSON online free. Tree view, file upload, private browser-only.
Related Guides & Tutorials
What is a JSON Payload? A Simple Guide for API Beginners
Understand JSON payloads in API requests and responses. Learn how data is structured and transmitted between applications using JSON.
What is a JSON Schema? A Practical Introduction to Data Validation
Discover JSON Schema for validating JSON data structures. Learn how to define schemas and ensure data integrity in your applications.
How to Work with Nested JSON (A Beginner's Guide to Accessing Data)
Learn how to navigate and access data in nested JSON structures. Beginner-friendly guide with practical examples for common scenarios.