JSON to Rust

Generate Rust structs with Serde attributes from JSON

JSON input

Options

Model
Serialization

Rust output

Paste JSON or load an example to generate Rust code.

What JSON to Rust generates

JSON to Rust turns an API response or any JSON sample into Rust structs. With Serde on, each struct derives Serialize and Deserialize. Automatic renaming checks Serde's own case rules and adds #[serde(rename_all = "camelCase")] (or another rule) only when it reproduces every key of that struct; keys that do not fit get #[serde(rename = "...")]. Optional fields get #[serde(default, skip_serializing_if = "Option::is_none")] so they stay absent when written back.

How to use
  1. 1.Paste JSON, upload or drop a .json file, or load one of the examples.
  2. 2.Set the root struct name and choose Debug, Clone and Serde derives.
  3. 3.Choose automatic renaming, a fixed rule, or per-field renames only.
  4. 4.Read the notes under the output, then copy the code or download models.rs.
How types are inferred
  • •Every array item is inspected, not just the first one, and objects in the same array are merged.
  • •A key missing from some objects is optional; a key that is sometimes null is nullable. The two are kept apart.
  • •1 and 2.5 in the same position widen to a decimal number; other mixes are reported.
  • •Empty arrays and values that are only ever null have no type evidence, so a generic type is used and a note explains why.
  • •Type mapping: string → String, integer → i64 (u64 or serde_json::Value beyond that), decimal → f64, boolean → bool, array → Vec<T>, object → struct, missing or null → Option<T>, unknown or mixed → serde_json::Value.
Limits and privacy

A sample shows what the data looked like once, not the full API contract. Review optional fields, generic types and number widths before relying on the code. Input is limited to 5 MB and 256 nesting levels; from 2 MB, generation waits for the Generate button. Everything runs in your browser and the JSON is never uploaded. Generic values need the serde_json crate even when Serde derives are off.

CodingTool is officially live on

Launched on StartupBaseCodingTool.dev - Free, Fast & Easy Developer Tools in One Place | Product HuntCodingTool - Featured on Startup FameFazier badgeListed on Turbo0Featured on Twelve ToolsFeatured on Findly.toolsLaunchpadly Startup DirectoryCodingTool.dev — Featured on Smol Launch