Skip to content

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

Rust Serde structs
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,
}
Need Go or TypeScript instead?JSON to Go →

Updated . Provided as is. Check the output before you rely on it in production.

How to use JSON to Rust Serde

  1. 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. 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. 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?
Serde is Rust's standard serialization framework: #[derive(Serialize, Deserialize)] generates conversion code at compile time, and serde_json applies it to JSON. This tool turns sample JSON into structs with those derives, Option<T> for nulls, optional pub fields and a camelCase or snake_case rename_all.
What does #[derive(Debug, Serialize, Deserialize)] mean?
These are derive macros that tell Rust's compiler to automatically generate trait implementations. Debug enables printing structs with println!, Serialize makes the struct convertible to JSON, and Deserialize allows parsing JSON back into the struct.
What does the rename_all option do?
rename_all applies a naming convention to all fields during serialization. For example, rename_all="camelCase" converts Rust snake_case field names to JSON camelCase. This bridges the naming convention gap between Rust and JSON APIs.
Why use Option<T> for null values?
Option<T> is Rust's safe way to represent nullable values. Option<String> means the field can be Some(value) or None. This forces you to handle missing data explicitly, preventing null pointer errors. The tool defaults to this for safety.

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

GET /api/json-to-rust-serde/ GET json-to-rust-serde
POST /api/json-to-rust-serde/ POST json-to-rust-serde