JSON to Python Dataclass Converter

Runs in your browser — your data is never uploaded.

Paste JSON and get Python dataclasses — or Pydantic models — with type hints already filled in. Field names are converted to snake_case, optional fields are wrapped in Optional and defaulted to None, and required fields are emitted first so the class actually imports. Nested objects become their own classes, declared before the class that uses them. Everything runs in your browser.

0 characters · runs entirely in your browser

How to use JSON to Python

  1. 1

    Paste a JSON sample.

  2. 2

    Choose dataclass or Pydantic, and set a root class name if you want one.

  3. 3

    Click “Generate” and copy the classes into your module.

Share

Embed this tool on your site

Paste this where you want the tool to appear. It runs entirely in your visitor's browser — no uploads, no account, no tracking.

Please keep the attribution line — it's what keeps these tools free.

Need a different size, a dark theme, or a different tool? Build an embed lets you preview it first.

Frequently asked questions

Why are required fields listed before optional ones?+

Because a dataclass with a defaulted field before a non-defaulted one raises TypeError at import time. Ordering here is correctness, not style — the generator reorders so the output runs.

Should I pick dataclass or Pydantic?+

Dataclasses are standard library and free — good for internal shapes you control. Pydantic validates and coerces at runtime, which is what you want at a boundary where the data is genuinely untrusted, like an incoming API response.

Why did my field name change?+

Python convention is snake_case, so userName becomes user_name and content-type becomes content_type. If you need the original key preserved for serialisation, add an alias — Pydantic supports that directly.

How are lists typed?+

As List[T] where T is the merge of every element in the sample, so a list of objects gets a real element class rather than List[Any].

Is my data sent anywhere?+

No. Both inference and code generation run in your browser, so a response containing real records stays on your machine.