🔄 JSON to Rust Struct

One-click convert JSON data to Rust struct definitions with serde tags and Option types

Zero Dependencies · Works Offline

📝 JSON Input

What is JSON to Rust Struct Converter?

The JSON to Rust Struct Converter is a free online developer tool that instantly converts JSON data into Rust struct definitions. It automatically identifies JSON field types and maps them to Rust types, supporting nested object struct generation, serde serialization tags, and Option type handling. Perfect for Rust developers who need to quickly generate type definitions from API responses or configuration files, combined with serde_json for automatic serialization/deserialization. All conversion happens locally in your browser — no data is ever uploaded to a server.

Core Features

How to Use

1. Paste your JSON data into the input area, or click "Load Example" to try it quickly.

2. Set the struct name and conversion options: serde tags, Option types, visibility, etc.

3. Click "Convert" or use Ctrl+Enter to execute.

4. View the generated Rust struct code in the result area below.

5. Click "Copy Code" to copy to clipboard, or download as a .rs file.

Use Cases

Web API Development

When building backends with Axum/Actix-web, quickly generate Rust structs from JSON request/response schemas with serde for automatic serialization.

Config File Parsing

Generate config struct definitions from JSON config files in Rust projects, ensuring type safety.

CLI Tool Development

Generate structs from JSON API responses for type-safe HTTP clients with reqwest+serde.

WASM Projects

Generate Rust structs from JavaScript JSON data for type-safe cross-language communication in WebAssembly.

Technical Background

serde is the most popular serialization framework in the Rust ecosystem, with serde_json as its JSON implementation. #[derive(Serialize, Deserialize)] enables automatic JSON encoding/decoding for structs. When Rust field names differ from JSON keys (e.g., Rust uses camelCase isVip while JSON uses is_vip), #[serde(rename="is_vip")] provides the mapping. Option is Rust's standard way to express nullable values — serde maps JSON null to None and present values to Some(T). Vec handles JSON arrays. Rust naming conventions recommend UpperCamelCase for structs and lowerCamelCase for fields, requiring rename tags when JSON uses snake_case.

âť“ FAQ

Does it support nested JSON?

Yes. Nested objects are automatically generated as separate Rust struct definitions.

How are null values handled?

With "Option types" enabled, null fields generate Option for Rust type safety.

Does it support serde tags?

Yes. Generates #[serde(rename)] and #[serde(default)] tags.

Is my data uploaded?

No. All processing happens locally in your browser. Your data never leaves your device.

What dependencies are needed?

Add serde = {version="1",features=["derive"]} and serde_json = "1" to Cargo.toml.

Can generated code be used directly?

Yes. Add serde dependencies and the generated code compiles directly.

JSON to Rust Struct Converter | No Signup, Client-Side · No Server Uploads

Feedback: dexshuang@google.com