Docelora
ToolsAboutContact
Developer tools

JSON to Python

Turn JSON into typed Python classes – standard dataclasses, Pydantic models for validation, or TypedDict for type-checking plain dictionaries.

Quick answer: paste a JSON sample – an API response works well – and the Python types appear instantly. Name the root type, adjust the options, then copy or download the code.

JSON to Python

Python types · nested objects · optional fields

Private: your code is processed in this browser tab and never uploaded.

How JSON types map to Python

JSONPython
stringstr
whole numberint
decimalfloat
true/falsebool
objectclass
arrayList[T]
null / optionalOptional[T] = None

Good to know

Related tools

Frequently asked questions

How do I convert JSON to a Python class?

Paste JSON, pick dataclass, Pydantic or TypedDict, and copy the code into your module.

Which style should I use?

Pydantic validates and converts incoming data and is common in FastAPI; dataclasses need no dependency; TypedDict adds type hints to plain dicts.

How do I load JSON into a dataclass?

Dataclasses do not convert nested dicts by themselves – use Pydantic, or a library such as dacite, or build the objects manually.

How are keys like firstName or full-name handled?

Fields are converted to snake_case. Pydantic output adds Field(alias="…") so the original key still parses.

Why are classes in reverse order?

Nested classes are defined before the classes that use them, so the module imports cleanly without forward references.

Does it work with Pydantic v2?

Yes – BaseModel and Field aliases work the same way in Pydantic v1 and v2.

Why are optional fields last?

Dataclass fields with defaults must come after fields without defaults.

Can I use the newer list[str] syntax?

Yes on Python 3.9+; the generator uses typing.List and Optional for compatibility.

Does it check types at runtime?

Only Pydantic does; dataclasses and TypedDict are hints for tools like mypy.

How are nested objects named?

From their JSON key in PascalCase – the "address" object becomes Address; array items get a singular name, so "orders" becomes Order.

What happens when array items differ?

All items are merged into one type. Keys missing from some items become optional, and an int that is sometimes a decimal becomes a floating-point number.

How is null handled?

A field that is null in your sample becomes nullable; if it is only ever null, its type cannot be known and a generic type is used – replace it with the real type.

Can I upload a .json file?

Yes – use Open file, or paste the text.

Are dates detected?

No. JSON has no date type, so dates stay strings – convert them after decoding if you need date objects.

Is it free?

Yes – no sign-up, no limits and no watermark.

Is my code uploaded?

No. Everything runs in your browser; nothing you paste is sent to Docelora.

Can I use the output in commercial projects?

Yes. The output is yours to use however you like.

Does it work on a phone or tablet?

Yes – the layout adapts to small screens, though long code is easier to read on a larger display.

How do I copy the result?

Use the Copy button under the result, or Download to save it as a file.

Which browsers are supported?

Current versions of Chrome, Edge, Firefox and Safari.

Last reviewed: 15 November 2026.