JSON Input

Rust Output

What Is JSON to Rust?

Rust uses structs for structured data. When you consume JSON with Serde, you need matching struct definitions. The JSON specification defines objects, arrays, strings, numbers, and booleans—but Rust needs explicit struct definitions for each nested object.

This tool generates Rust structs from your JSON. Enable Serde for Serialize/Deserialize derives. Enable Option Types for optional fields. The output works with serde_json::from_str and serde_json::to_string.

Conversion runs entirely in your browser. Your JSON is never sent to a server.

When JSON to Rust Helps

When building Rust apps that consume REST APIs, you need typed structs. Paste a sample response here to generate matching structs with Serde support.

How to Use This Tool

1

Paste or Upload JSON

Copy your JSON and paste it into the left editor. You can also click Upload to load a file. Use the Sample button for example data. Set the struct name and options in the config panel.

2

Review the Generated Structs

The right panel shows the generated Rust structs. Nested objects become separate structs. Arrays become <code>Vec&lt;T&gt;</code>. If your JSON has invalid syntax, fix it first using the JSON Formatter or JSON Validator.

3

Copy or Download

Use Copy or Download to get the code. Add serde and serde_json to your Cargo.toml. Paste into your Rust project.

JSON to Rust Examples

Here is an example of generating Rust structs from a JSON object.

Example: Subscriber record

JSON input:

Input

Generated Rust output:

Output

When JSON to Rust Helps

Most developers need this when integrating with REST APIs. Pasting it here gives you Serde-compatible structs you can use immediately.

If you need to merge two JSON files first, there's a separate JSON Merge tool for that.

API responses, config files, or data exports are often JSON. Running them through here helps you generate Rust structs.

Frequently Asked Questions

Serde or manual deserialization?

Serde is the standard for JSON in Rust. It generates Serialize and Deserialize via derive macros. Add serde = { version = "1.0", features = ["derive"] } and serde_json to Cargo.toml.

What about Option for null fields?

Enable Option Types for optional JSON fields. This wraps nullable fields in Option<T>.

Is my data sent anywhere?

No. Generation runs entirely in your browser. No data is sent to any server.

Can I use #[serde(rename)]?

Yes. The generator adds #[serde(rename = "jsonKey")] when the Rust field name (snake_case) differs from the JSON key (camelCase).

What about nested objects?

Nested JSON objects become separate Rust structs. Arrays become Vec<T> of those struct types.

Related Tools

For Rust JSON, see Serde and serde_json. For JSON, see the JSON specification.