JSON to Rust

Convert JSON to Rust structs with serde derives, snake_case fields, renames and Option types. Free and runs in your browser.

How to convert JSON to Rust

  1. Paste a JSON object or array, for example a response from the API you are calling.
  2. Set the name of the root type.
  3. Copy the generated Rust code into your project.

What you get

Tips for accurate results

The generator only knows the sample you paste. Include arrays with several items and responses where optional fields are present, so it can tell which keys are always there, which can be null and which numbers have decimals.

Frequently asked questions

Is my JSON sent to a server?

No. The code is generated in your browser, so API responses and other private data never leave your device.

Which crates do I need?

Add serde with the derive feature and serde_json: cargo add serde --features derive and cargo add serde_json. Then parse with serde_json::from_str::<Root>(&text).

How are Rust keywords handled?

Keys like type or match become raw identifiers (r#type), which serde maps back to the original name. self, super and crate cannot be raw identifiers, so they get a trailing underscore and a rename.

Why i64 and f64?

Whole numbers become i64 and numbers with decimals f64, which cover any value JSON parsers usually produce. Narrow them (u32, i16…) if you know the range.