JSON to Rust Converter
Generate serde-ready Rust structs from a JSON payload, with rename attributes and Option types applied where they belong.
Your data stays on your device
Input — JSON
- characters
- 0
- lines
- 0
- size
- 0 B
Output — Rust
- characters
- 0
- lines
- 0
- size
- 0 B
Options
About this tool
Rust models JSON through serde, and the derive macros do almost all the work — provided the struct fields line up with the JSON keys. Since Rust uses snake_case and many APIs do not, rename attributes are usually required.
The generator emits snake_case fields with serde rename attributes wherever the original key differs, wraps nullable values in Option<T>, and creates a separate struct for each nested object.
How to use this tool
- Paste your JSON sample.
- Set the root struct name.
- Choose which derives to include and whether to use a container-level rename_all attribute.
- Press Generate and paste the structs into your crate.
Key features
- Serialize and Deserialize derives, plus Debug and Clone as options
- Field-level serde rename, or a single container-level rename_all attribute
- Option<T> for null and inconsistently present fields
- Vec<T> for arrays with element types unified
- i64 and f64 inferred separately from the sample
- Rust keywords escaped using the raw identifier syntax
Example
Input — JSON
{"userId":8,"nickname":null}Output — Rust
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Root {
#[serde(rename = "userId")]
pub user_id: i64,
pub nickname: Option<String>,
}Good to know
- Heterogeneous arrays become Vec<serde_json::Value>, since Rust requires a single element type.
- No use statements are emitted; add serde and serde_json to your Cargo.toml yourself.
- Lifetimes and borrowed types are not generated — every string field is an owned String.
Frequently asked questions
rename_all or per-field rename?
rename_all is much cleaner when every key follows the same convention, such as camelCase throughout. Per-field renames are necessary when keys are inconsistent.
Why Option<T> instead of a default?
Option makes absence explicit and forces the calling code to handle it. serde also supports #[serde(default)], but that silently substitutes a zero value.
What crates do I need?
serde with the derive feature, plus serde_json for parsing. Both are the standard choice and are already in most Rust projects that touch JSON.
How are keys that are Rust keywords handled?
They are emitted as raw identifiers such as r#type, with a serde rename back to the original key.
Your data stays on your device
Your data is processed locally in your browser and is not uploaded to our server. This page keeps working after you go offline, because there is nothing to send.