What this does
Generates Rust structs from a JSON sample, annotated forserde so you can deserialize with serde_json. Field names are converted to snake_case, and a #[serde(rename = "...")]attribute is added wherever the Rust name differs from the JSON key.
Example
Input
{
"id": 42,
"name": "Ada",
"verified": true,
"tags": [
"admin",
"dev"
],
"orders": [
{
"sku": "A1",
"qty": 2
},
{
"sku": "B2",
"qty": 1,
"note": "gift"
}
]
}Output with default options
use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
pub id: i64,
pub name: String,
pub verified: bool,
pub tags: Vec<String>,
pub orders: Vec<Order>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Order {
pub sku: String,
pub qty: i64,
pub note: Option<String>,
}
How values are mapped
- Whole numbers become
i64(ori32when you pick that), other numbersf64, stringsString, booleansbool. - Arrays become
Vec<T>; nested objects become their own structs. - A field missing from some objects, or sometimes
null, becomesOption<T>. - Arrays of mixed types become an
#[serde(untagged)]enum. A value that is alwaysnullbecomesOption<serde_json::Value>.
Options
Choose field visibility (pub, pub(crate), or private), force integers to i32 or i64, and toggle the Debug,Clone, and PartialEq derives. Skip serializing Noneadds skip_serializing_if so absent options are omitted when you serialize back to JSON.
Things to know
Dates stay as String; add chrono or time types yourself if you want parsed timestamps. As with every inference tool, the structs match the sample: include several objects when some fields are sometimes missing.
Privacy
Generation runs in a Web Worker in your browser. The JSON is never uploaded.