JSON to Rust
Paste JSON and get Rust structs with serde Serialize/Deserialize, snake_case fields, rename attributes and Option for missing keys.
JSON
Rust
How the Rust structs are built
- Structs derive
SerializeandDeserializefor serde. Fields use snake_case with#[serde(rename = "…")]when the JSON key is different. - Keys that can be missing or
nullbecomeOption<T>withdefault, and are skipped when serializing. - Whole numbers become
i64, decimalsf64. Mixed or unknown values becomeserde_json::Value.
Parse JSON with serde_json
# Cargo.toml
[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"let data: Root = serde_json::from_str(&json)?;
println!("{:?}", data);Smart type detection
Objects inside arrays are merged into one type, so a key that appears in only some items is still included (as optional). Names come from the keys, and plural keys become singular: comments → Comment. Whole numbers and decimals in the same field become a decimal type. Everything runs in your browser; your JSON is never uploaded.
More free tools
JSON to TypeScriptGenerate TS interfaces from sample data.JSON to GoGo structs with json tags from sample JSON.JSON to PythonPydantic models or dataclasses from JSON.JSON to JavaJava records or POJOs with Jackson annotations.JSON to C#C# classes for System.Text.Json.JSON ViewerTree view, search, copy path. Handles huge files.JSON FormatterBeautify or minify JSON in one click.JSON ValidatorClear errors with exact line and column.