# JSON to Rust Struct Converter

Convert JSON data into Rust structs with serde Serialize/Deserialize derives, snake_case fields, and serde rename attributes

> Canonical page: https://elysiatools.com/en/tools/json-to-rust

- **Category:** Development

- **Keywords:** json, rust, struct, serde, convert, transform, codegen, json to rust, Serialize, Deserialize, backend, dto

## Overview

The JSON to Rust Struct Converter instantly transforms JSON payloads into strongly typed Rust structures. It automatically generates serde serialization and deserialization derives, converts field names to idiomatic snake_case, and appends serde rename attributes to preserve original JSON keys during API communication.

## Inputs

- **JSON Input** (textarea): { "name": "Alice", "age": 30, "roles": \["admin", "user"\], "address": { "city": "Shanghai", "zip": "200000" } }
- **Root Type Name** (text): Root
- **Wrap with Option** (checkbox)

## When to use

- When integrating external REST APIs in Rust and needing to define strongly typed Data Transfer Objects (DTOs).
- When parsing configuration files or JSON payloads into Rust structs using the serde library.
- When migrating legacy JavaScript or TypeScript codebases to Rust and translating interface definitions.

## How it works

- Paste your raw JSON payload into the JSON Input text area.
- Specify the Root Type Name and choose whether to wrap fields in Option to handle nullable or missing values.
- Copy the generated Rust structs, which include Serialize, Deserialize, and serde rename attributes.

## Use cases

- Generating Rust structs for complex API responses from third-party services like Stripe or GitHub.
- Creating configuration structs for parsing local config.json files.
- Speeding up backend development by converting frontend JSON payloads into Rust DTOs.

## Frequently asked questions

### Does the converter support nested JSON objects?

Yes, it recursively generates nested Rust structs for all child objects found in the JSON payload.

### How does it handle camelCase or kebab-case JSON keys?

It converts them to idiomatic Rust snake_case and adds a #[serde(rename = "...")] attribute.

### Can I make all fields optional in the generated structs?

Yes, enabling the 'Wrap with Option' setting wraps struct fields in Rust's Option type.

### Which Serde traits are derived by default?

The generated structs derive both Serialize and Deserialize traits.

### Does it support JSON arrays?

Yes, JSON arrays are converted into Rust Vec collections containing the corresponding type.

## Related tools

- [Data URI Generator](https://elysiatools.com/en/tools/data-uri-generator): Convert files into Data URIs (Base64 or percent-encoded) for inlining images, fonts, and assets directly into HTML, CSS, or Markdown
- [JSON Schema to Zod Schema Converter](https://elysiatools.com/en/tools/json-schema-to-zod-schema-converter): Convert JSON Schema JSON/YAML definitions into ready-to-use Zod schemas with nested objects, arrays, enums, and common validation rules
- [JSON to C# Class Converter](https://elysiatools.com/en/tools/json-to-csharp): Convert JSON data into C# classes with PascalCase properties, JsonPropertyName attributes, and nested type inference
- [JSON to Go Struct Converter](https://elysiatools.com/en/tools/json-to-go): Convert JSON data into Go struct definitions with json struct tags, exported PascalCase fields, and nested type inference
- [JSON to Java Class Converter](https://elysiatools.com/en/tools/json-to-java): Convert JSON data into Java classes with Jackson @JsonProperty annotations, private fields, getters, and setters
- [JSON to Kotlin Data Class Converter](https://elysiatools.com/en/tools/json-to-kotlin): Convert JSON data into Kotlin data classes with @SerializedName annotations, nullable handling, and nested type inference
- [JSON to TypeScript Converter](https://elysiatools.com/en/tools/json-to-typescript): Convert JSON data into TypeScript interfaces or type aliases with union types, optional fields, and nested object inference
- [Log Sequence Diagram Converter](https://elysiatools.com/en/tools/log-sequence-diagram-converter): Convert structured service logs into Mermaid or PlantUML sequence diagrams, with optional latency and error annotations

## Samples

- [Web Data Serialization Rust Samples](https://elysiatools.com/en/samples/web-serialization-rust): Web Rust data serialization examples including JSON serialization, deserialization, and XML parsing
- [Terraform Plan JSON Samples](https://elysiatools.com/en/samples/terraform-plan-json-samples): Sample Terraform plan JSON files exported from terraform show -json style payloads for dependency visualization and change review
- [Chat Transcript JSON Samples](https://elysiatools.com/en/samples/chat-transcript-json): JSON examples for multi-role chat transcripts
- [JSON Samples](https://elysiatools.com/en/samples/json): JSON (JavaScript Object Notation) format examples from simple to complex structures

## Related content

- [JSON to Typed Code Generators](https://elysiatools.com/en/hubs/json-to-typed-code-generators): Generate typed models from JSON or schema evidence for TypeScript, Go, Rust, Kotlin, Java, C#, and Zod validation workflows.
