MagmaNex LogoMagmaNex

JSON to Rust Struct

Generate Rust structs (serde) from JSON

What does this tool do?

JSON to Rust converts the JSON you paste into serde-compatible Rust struct definitions. It saves time for developers who need to deserialize an API response or config file in Rust, and the whole conversion runs locally in your browser.

How to use it

  1. Paste or type your data into the left field.
  2. The result is generated instantly on the right.
  3. Use the Copy button to grab the output.

Comes ready for serde

Every generated struct carries the #[derive(Debug, Serialize, Deserialize)] attribute, and the file starts with use serde::{Deserialize, Serialize};. That means you can paste the output straight into your project and parse it with serde_json::from_str. Field names that arrive as camelCase or other styles are converted to snake_case, and a #[serde(rename = "...")] attribute is added automatically to preserve the original key so you stay aligned with Rust naming conventions.

How type inference works

The tool infers Rust types from the values: whole numbers become i64, decimals become f64, booleans become bool, and text becomes String. Nested objects produce their own structs named after the field, and arrays become Vec<T> based on the first element. null values are represented as Option<serde_json::Value>, and anything ambiguous falls back to serde_json::Value so the output always compiles.

Frequently asked questions

Can I change the top-level struct name?

Yes. Type your preferred name into the struct name field; the root struct uses it, while nested structs are derived from their field names.

Is the original JSON key kept when a field is converted to snake_case?

Yes. When a field is renamed to snake_case, the tool adds a #[serde(rename = "originalKey")] line so deserialization still matches the real JSON key.

How are empty arrays and null values handled?

Empty arrays become Vec<serde_json::Value> because the element type is unknown, and null values are emitted as Option<serde_json::Value>.

Is JSON to Rust Struct free?

Yes. JSON to Rust Struct and all 300+ tools on MagmaNex are completely free with no signup or account required.

Is my data safe?

Yes. Everything runs locally in your browser. The data you enter is never sent to a server, stored, or shared.

Does it work on mobile?

Yes. JSON to Rust Struct works on phones, tablets and desktops — no app download needed.

🔒 Privacy: everything runs in your browser, your data is never sent to a server.

Related Tools

📝 Related Articles

Popular Tools