JSON to Rust Serde
Convert JSON to Rust structs with Serde Serialize and Deserialize derives, rename_all options, Option<T> for nulls and pub fields.
JSON to Rust Serde
use serde::{Serialize, Deserialize};
use serde_json;
#[derive(Debug, Serialize, Deserialize)]
pub struct User {
pub id: i64,
pub name: String,
pub email: String,
pub age: i64,
pub active: bool,
pub score: f64,
pub tags: Vec<String>,
pub address: Address,
pub metadata: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Address {
pub street: String,
pub city: String,
}Updated . Provided as is. Check the output before you rely on it in production.
How to use JSON to Rust Serde
- 1
Paste your JSON data
Paste a JSON object or array. Strings become String, integers i64, decimals f64, booleans bool and null Option<T>.
- 2
Configure struct options
Set the root struct name, choose a rename_all strategy (camelCase or snake_case), and toggle Option<T> for nulls and public fields.
- 3
Review and copy the structs
The output uses #[derive(Serialize, Deserialize)] with the right serde attributes; nested objects become separate structs. Copy it next to your serde dependency.
Questions and answers
What is Serde and why is it the standard for Rust JSON?
What does #[derive(Debug, Serialize, Deserialize)] mean?
What does the rename_all option do?
Why use Option<T> for null values?
Use it as an API
JSON to Rust Serde is also callable as a free HTTP JSON API at
https://aidevhub.io/api/json-to-rust-serde/ — GET with query
parameters or POST with a JSON body, no authentication, CORS enabled, fair use
(abusive traffic is throttled at the edge; there is no per-request quota header). Responses return
{ ok, tool, result, meta }.
curl -s -X POST https://aidevhub.io/api/json-to-rust-serde/ \
-H "Content-Type: application/json" \
-d '{"json":"{\"id\":1,\"name\":\"Alice\"}","root_name":"User"}' Machine-readable contract: /api/tool/json-to-rust-serde.json All API endpoints: /agents/ LLM site index: /llms.txt
For AI agents: how to call this tool
Machine-readable contract, endpoints and examples. Humans can ignore this section.
Best Path For Builders
Dedicated API endpoint
Deterministic outputs, machine-safe contracts, and production-ready examples.
Dedicated API
https://aidevhub.io/api/json-to-rust-serde/ OpenAPI: https://aidevhub.io/api/openapi.yaml