About the JSON to Rust
Rust's reputation for memory safety comes with a cost, namely a very strict type system. If you need to consume an external API's JSON data in your Rust program, you need to write a struct with the same fields as in the JSON, and define what type each field is in Rust. Writing these structs for every large nested API response is repetitive work. That's why this JSON to Rust converter can come in handy; just paste your JSON input and it will generate the structs you need to deserialize the data in Rust. This tool was built with a strong focus on privacy, so your JSON data will always stay on your computer and never leave the browser.
Key Features of JSON to Rust
- Automated type inferenceAnalyze your JSON values and select the correct Rust types and structure for the deserializer to use.
- Smart optional fieldsWant to make fields optional in your deserialized struct? Toggle the "Fields" dropdown and select either "Required" or "Optionals".
- Deep nesting resolutionPaste any JSON you want to deserialize in Rust and the tool will figure out all the nesting needed for the struct(s).
- Custom root nameYou can customize the name of the root struct using the "Root struct name" field.
- 100% local processingYour JSON data is parsed and converted to Rust code only in your browser.
How to Use JSON to Rust
- Open the JSON to Rust converter page.
- Paste your JSON in the "JSON input" textarea.
- Optionally, change the name of the root struct by typing in the "Root struct name" field. By default, the name will be "Root".
- Use the "Fields" dropdown to select either "Required" or "Optionals" for the struct fields.
- Click the purple "Generate" button and wait for the tool to generate the Rust code.
- Check the generated structs in the "Output" section underneath the "Rust code" tab.
- Click "Copy" to copy the code to your clipboard or "Download" to save it as a .rs file to your computer.
JSON to Rust Examples
A struct with Serde derives.
{"id":7,"name":"Amal","active":true,"tags":["admin"]}use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
pub id: i64,
pub name: String,
pub active: bool,
pub tags: Vec<String>,
}