Start a project

Tool 271 of 450 · Python

JSON to Python Dataclass

Generate Python dataclasses, TypedDicts or Pydantic models from sample JSON, with nested types and optionals.

JSON to Python Dataclass

Your input

Result

Python
ClassFieldsOptional

01

What it does

Generate Python dataclasses, TypedDicts or Pydantic models from sample JSON, with nested types and optionals.

  • dataclass, TypedDict, Pydantic v2 and msgspec.Struct
  • Nested objects become their own classes, named from the key
  • Arrays of objects merged: keys missing in some become optional
  • camelCase keys to snake_case with aliases

02

Private by design

Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

03

What you get

Python classes ready to paste, with a Copy and a Download button on every result.

  • Python
  • Dataclass
  • Pydantic

Why it matters

Typing an API response by hand is slow and easy to get wrong, especially when a key only appears in some items of a list.

This reads every item of every list, so optional fields are marked optional, and keys that aren't valid Python names keep a working alias.

How to use it

  1. Type or paste your input; the example shows the format.
  2. Press Generate. Results also update as you type.
  3. Read the summary line, then the table, notes or output below it.
  4. Copy or download what you need. Nothing leaves this page.

FAQ

Why are some fields Optional?

They were null in the sample, or missing from at least one item in a list of objects.

How are camelCase keys handled?

Field names become snake_case. Pydantic gets Field(alias=…), msgspec gets rename, and dataclasses note the original key so you can map it.

Can I use it for TypedDict with keys that aren't valid names?

Yes: TypedDicts with keys like 'first-name' are written in the functional form, which allows any key.

Is my input uploaded?

No. The tool runs in your browser and nothing you type, paste or open is sent anywhere.

Can I rely on the result?

It follows the public specification or formula named on this page and says where it simplifies. Check anything critical against the official tool or documentation before you ship it.

Work with me

Want a site that gets these right?

I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

All developer tools · Back to leej.uk