JSON to Rust Struct
Generate Rust structs with serde derives and Option fields from any JSON.
Runs in your browser. Nothing is uploaded.
Waiting for JSON
Rust types appear here.What this does
Paste JSON and get Rust structs deriving Serialize and Deserialize for serde. Nested objects become their own structs; arrays of objects are merged into one struct.
Option and defaults
A value that is sometimes null becomes Option<T>. A key missing from some items also gets #[serde(default)] so decoding does not fail, and is skipped when serializing None. Whole numbers are i64, decimals f64, unknown values serde_json::Value.
Names
Fields are snake_case; when that differs from the JSON key (firstName → first_name) a #[serde(rename)] keeps the original. Reserved words become raw identifiers such as r#type. Two objects with the same shape share one struct.
Setting up serde
Add serde = { version = "1", features = ["derive"] } and serde_json = "1" to Cargo.toml, then decode with let root: Root = serde_json::from_str(&text)?. Keys the struct does not declare are ignored by default, so APIs that add fields keep working; add #[serde(deny_unknown_fields)] if you want strict parsing. Every struct also derives Debug and Clone, so you can print and copy values straight away.
Integers, floats and decode errors
A field becomes i64 when every sample was a whole number and f64 as soon as one had a decimal. If the real data later sends 1.5 for an i64 field, decoding fails with invalid type: floating point, expected i64. Ids larger than i64 can hold need u64, and money is safer as a string or a decimal crate type than as f64. Mixed or empty arrays become Vec<serde_json::Value>, which you can inspect with methods like as_str and as_i64.
More json tools
All json tools- JSON to TypeScriptTurn any JSON into TypeScript interfaces. Nested types named, optional keys detected.
- JSON to Go StructGenerate Go structs with json tags from any JSON. Nested structs named, pointers for nullable values.
- JSON to Kotlin Data ClassGenerate Kotlin data classes from JSON, for kotlinx.serialization, Gson, or plain Kotlin.
- JSON to Java ClassGenerate Java records or POJO classes with Jackson annotations from any JSON.
- JSON to Python DataclassGenerate Python dataclasses, Pydantic models, or TypedDicts with type hints from any JSON.
- JSON to C# ClassGenerate C# classes for System.Text.Json or Newtonsoft from any JSON. Nullable types detected.
- JSON to Dart ClassGenerate null-safe Dart classes with fromJson and toJson from any JSON. Made for Flutter.
- JSON to Swift CodableGenerate Swift Codable structs with CodingKeys from any JSON.