JSON to Rust Struct

Generate Rust structs from JSON

About JSON to Rust Struct

JSON to Rust Struct generates a single Root struct annotated with #[derive(Debug, Serialize, Deserialize)] and one field per top-level JSON key, entirely in your browser — nothing is uploaded to a server. Strings, numbers, and booleans map to String, f64, and bool; arrays become Vec of serde_json::Value and nested objects become serde_json::Value, since nested values aren't recursively converted into their own structs. The Serialize/Deserialize derives assume your project already depends on the serde and serde_json crates.

How to use JSON to Rust Struct

  1. 1Paste your JSON into the input box.
  2. 2Click 'Convert' to generate a Rust struct from the top-level properties.
  3. 3Review the output and add nested struct types by hand where needed.
  4. 4Click 'Copy' to copy the code into your project.

Frequently Asked Questions

Is JSON to Rust Struct free to use?

Yes, it's completely free with no signup required.

Does it generate nested structs for nested JSON?

No — only top-level keys become typed fields. Nested objects are typed as serde_json::Value and arrays as Vec<serde_json::Value>, rather than generating separate nested struct types.

Do I need any dependencies to use the generated code?

Yes — the derive(Serialize, Deserialize) attribute requires the serde crate (with the derive feature) and serde_json in your Cargo.toml.

Is my data uploaded to a server?

No, generation happens entirely in your browser.

Tips & Tricks

  • Add serde with the derive feature, plus serde_json, to your Cargo.toml before using the generated struct.
  • For nested objects or arrays of objects, manually define additional struct types and update the field types to reference them.
  • Numbers always map to f64 — change to a specific integer type like i32 or u64 if that better matches your data.
  • Field names are used exactly as written in your JSON; rename to snake_case and add a serde rename attribute if your JSON uses a different naming convention.