# JSON to Rust

> Infer Rust structs from a JSON sample. Nested objects become named structs with serde renames. Keys missing from some objects in an array are optional. Conversion stays in the tab.

Runs in your browser. Nothing is uploaded.

[Convert](https://toolbuddy.dev/categories/convert.md)

## About this tool

Infer Rust structs from a JSON sample. Objects become named structs with serde Serialize and Deserialize. Camel-case keys become snake_case fields with a rename. Keys missing from some objects in an array, and a JSON null next to a concrete value, become Option. Whole numbers stay i64. Other numbers become f64.

How to use: paste JSON, copy the structs. A root array of objects is type Root = Vec<RootItem>. Empty objects become HashMap<String, serde_json::Value> and empty arrays become Vec<serde_json::Value>. This is a starting point. It does not add methods, enums, or validation.

Example: {"id":1,"name":"Ada","address":{"city":"London"}} yields struct Root and struct Address. The snippet expects the serde and serde_json crates. Related: JSON to Go for structs, JSON to TypeScript for interfaces, JSON to Python for dataclasses.

The sample stays in the tab. Nothing is uploaded. After the page loads, conversion works offline.

## FAQ

### Does this compile the Rust code?

No. It writes struct declarations you can paste into a file. It does not run rustc, and the JSON sample stays in the tab.

## Related Convert tools

- [JSON ↔ YAML](https://toolbuddy.dev/tools/json-yaml.md): Convert JSON to YAML and YAML back to JSON in the browser. Paste a config, Kubernetes snippet, or API fixture and copy the other format. Parsing uses js-yaml locally. Documents are never posted to a converter.
- [JSON ↔ TOML](https://toolbuddy.dev/tools/json-toml.md): Convert JSON objects to TOML and TOML documents back to JSON in the browser. Handy for Cargo.toml, pyproject, and app config fragments. Parsing stays on-device.
- [JSON ↔ XML](https://toolbuddy.dev/tools/json-xml.md): Convert JSON objects to XML and XML documents back to JSON. Useful for SOAP leftovers, RSS, and mixed API stacks. XML is parsed with the browser DOMParser so payloads stay on the device.
- [JSON ↔ CSV](https://toolbuddy.dev/tools/json-csv.md): Turn an array of JSON objects into CSV, or parse CSV headers into JSON objects. Quote-aware parsing runs in the tab so spreadsheets of IDs and emails are not uploaded to a conversion service.
- [JSON to SQL](https://toolbuddy.dev/tools/json-sql.md): Turn a JSON object or array of objects into SQL INSERT statements. Set a table name, copy the query, and keep rows on the device instead of pasting fixtures into a hosted converter.
- [CSV ↔ TSV](https://toolbuddy.dev/tools/csv-tsv.md): Convert comma-separated values to tab-separated values and back, preserving quoted fields. A small delimiter swap for dumps you would rather not paste into a spreadsheet SaaS.
