ToolFeather
Developer / SEORuns in your browser

JSON to Python Dataclass & Pydantic Generator

Turn a JSON sample into typed Python: standard-library dataclasses or Pydantic v2 models, with snake_case field names, aliases for the original keys, and X | None for optional values.

Quick presets

JSON to Python Class

JSON
Python

Runs in your browser — nothing you enter is uploaded or stored.

ToolFeather · JSON → Python
Scratchpad auto-saved
Stored in this browser (localStorage)
Step-by-step~40s read

How it works — in four simple steps

No signup and nothing to install — it all runs in your browser.

1

Add your JSON

Paste it into the left box, press Open file, or drag a .json file onto it. Sample loads a realistic example.

2

Set the options

Adjust the options above the boxes — the output updates instantly as you change them.

3

Check the result

Read the status line: it reports rows, keys and any value that couldn't be represented in Python.

4

Copy or download

Copy the Python or download it as a .py file. Nothing was uploaded at any point.

Pro tip

Pydantic mode keeps the original keys as aliases, so Model.model_validate(raw_json) just works.

Features

Named types

Choose the root type name; nested objects become their own named types, and identical shapes are merged.

dataclass or Pydantic

Standard-library @dataclass, or Pydantic v2 models with Field(alias=…) for keys that aren't valid Python names.

Private by design

Parsing and conversion run in your browser with JavaScript — your data is never uploaded, logged or stored.

About the JSON to Python Class

Typed models make JSON-handling code safer and easier to autocomplete. This generator infers a class for every object in your JSON — the root, each nested object, and the items of each array (singularised: books → Book) — and writes them dependency-first, so every class is defined before it's used.

Field names are converted to PEP 8 snake_case (inStock → in_stock); keywords like class or from get a trailing underscore. In Pydantic mode the original key is kept with Field(alias="inStock"), so Model.model_validate(data) works on the raw JSON. In dataclass mode, renamed keys are noted in a comment, since dataclasses don't do aliasing. Types follow modern syntax: list[str], dict[str, Any] and int | None.

Keys missing from some objects, or sometimes null, become X | None = None and are placed after the required fields, as dataclasses require. The file starts with from __future__ import annotations, so the | syntax works on Python 3.7+, and only the imports actually used are included.

Examples

A book record with camelCase keys, a nested publisher, a list of authors and an optional field.

JSON input
{
  "isbn": "978-0131103627",
  "title": "The C Programming Language",
  "inStock": true,
  "price": 45.5,
  "publisher": { "name": "Prentice Hall", "country": "US" },
  "authors": [ { "firstName": "Brian", "lastName": "Kernighan" }, { "firstName": "Dennis", "lastName": "Ritchie", "died": 2011 } ]
}
Python output
from __future__ import annotations

from dataclasses import dataclass


@dataclass
class Author:
    first_name: str  # JSON key: "firstName"
    last_name: str  # JSON key: "lastName"
    died: int | None = None


@dataclass
class Publisher:
    name: str
    country: str


@dataclass
class Book:
    isbn: str
    title: str
    in_stock: bool  # JSON key: "inStock"
    price: float
    publisher: Publisher
    authors: list[Author]

This output was produced by the converter on this page with root name Book (switch Style to Pydantic for Field aliases) — load it with the “Book API” preset above and change any option to see the effect.

How JSON maps to Python

In JSONBecomes in Python
"name": "Ada"name: str
36 / 36.5int / float
Nested objectits own class
["a"]list[str]
Missing or null in some itemsx: int | None = None
Key inStockin_stock + Field(alias="inStock") (Pydantic)
Key classclass_

Things that trip people up

JSON vs Python at a glance

PropertyJSONPython
SpecificationRFC 8259 (2017) · ECMA-404dataclasses (3.7+) · Pydantic v2
File extension.json.py
Media typeapplication/jsontext/x-python
Data typesstring, number, boolean, null, object, arraystr, int, float, bool, list, None
CommentsNoYes
NestingUnlimitedNamed classes

Frequently asked questions

5 answers
How do I convert JSON to a Python dataclass?
Paste the JSON, keep the @dataclass style, and copy the classes. Nested objects become their own dataclasses, defined before the classes that use them.
Can it generate Pydantic models?
Yes — choose Pydantic v2 BaseModel. Keys that aren't valid Python names get Field(alias=...) so validation works on the original JSON.
How are optional fields handled?
Keys missing from some objects, or null in some, are typed X | None with a default of None and listed after the required fields.
Which Python version is needed?
The output uses from __future__ import annotations, so it imports on Python 3.7+; Pydantic v2 itself needs 3.8 or newer.
Is my data uploaded anywhere?
No. The JSON is parsed and converted by JavaScript in your browser tab; nothing is sent to a server, so it is safe for internal exports, customer lists and configuration files with secrets.