>_devtools

JSON to Rust Struct Converter

Generate Rust structs with serde derives from a JSON sample, with visibility and derive options.

What this does

Generates Rust structs from a JSON sample, annotated forserde so you can deserialize with serde_json. Field names are converted to snake_case, and a #[serde(rename = "...")]attribute is added wherever the Rust name differs from the JSON key.

Example

Input

{
  "id": 42,
  "name": "Ada",
  "verified": true,
  "tags": [
    "admin",
    "dev"
  ],
  "orders": [
    {
      "sku": "A1",
      "qty": 2
    },
    {
      "sku": "B2",
      "qty": 1,
      "note": "gift"
    }
  ]
}

Output with default options

use serde::{Serialize, Deserialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
    pub id: i64,

    pub name: String,

    pub verified: bool,

    pub tags: Vec<String>,

    pub orders: Vec<Order>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Order {
    pub sku: String,

    pub qty: i64,

    pub note: Option<String>,
}

How values are mapped

  • Whole numbers become i64 (or i32 when you pick that), other numbers f64, strings String, booleans bool.
  • Arrays become Vec<T>; nested objects become their own structs.
  • A field missing from some objects, or sometimes null, becomes Option<T>.
  • Arrays of mixed types become an #[serde(untagged)] enum. A value that is always null becomes Option<serde_json::Value>.

Options

Choose field visibility (pub, pub(crate), or private), force integers to i32 or i64, and toggle the Debug,Clone, and PartialEq derives. Skip serializing Noneadds skip_serializing_if so absent options are omitted when you serialize back to JSON.

Things to know

Dates stay as String; add chrono or time types yourself if you want parsed timestamps. As with every inference tool, the structs match the sample: include several objects when some fields are sometimes missing.

Privacy

Generation runs in a Web Worker in your browser. The JSON is never uploaded.