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
- Smart Type Mapping: Auto-detects string→String, number→i32/f64, boolean→bool, array→Vec
, null→Option - Nested Structs: Nested JSON objects are automatically generated as separate struct definitions
- Serde Tags: Generates #[serde(rename="xxx")] and #[serde(default)] tags for serde_json compatibility
- Option Types: Null fields generate Option
for Rust type safety - Visibility Control: Choose pub or private fields for different module designs
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
âť“ 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
Does it support serde tags?
Yes. Generates #[serde(rename)] and #[serde(default)] tags.
Is my data uploaded?
No. Everything runs locally: JSON to Rust Struct and other values are processed on your device, never sent to a server. 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.