One document, or several samples as JSON Lines.
Options for Python

Convert JSON to Python classes

Paste a JSON sample and get Pydantic v2 models (or plain dataclasses) with modern type hints: str, int, float, bool, list[...], X | None for nullable or optional fields, and nested classes defined before the classes that use them. Keys that aren't Python names become snake_case fields with a Field(alias=...) back to the original key.

The output is checked for valid Python syntax in the tests. It runs entirely in your browser.

Need a different language? See all JSON-to-code converters.

JSON to Python Pydantic & Dataclass — frequently asked questions

Pydantic or dataclasses?
Pick either under Options. Pydantic models validate at runtime and read the original keys through aliases; dataclasses are dependency-free, with the same names and types.
What if some records have fields that others don't?
Every item of every array and every sample is read, not just the first. A field missing from some records comes out optional, a field holding two kinds of value becomes a union (or the language's any-value type), null beside a value makes it nullable, and a list of records at the top level gets an item type plus an alias for the list. Paste several samples as JSON Lines, one per line, and they're merged the same way.
Is my JSON uploaded anywhere?
No. Parsing and code generation run entirely in your browser with JavaScript — your JSON never leaves your device, so it's safe to paste API responses and other sensitive payloads. It's free with no sign-up.

Spotted a bug or have a suggestion?

Found something broken, have an idea, or just want to say thanks about any of our tools? Every message reaches a real person.