JSON to Python Converter

Generate dataclasses or TypedDicts from JSON.

Runs in your browser Free · no accountFile upload supported

JSON

Python

This conversion happens locally in your browser. Your files are never uploaded.

About the JSON to Python converter

Type hints turn an untyped dictionary into something your editor and type checker can actually help with. Writing them out for a large API response by hand is tedious enough that most people skip it.

Paste a sample and get dataclasses or TypedDicts, with imports included and nested objects given their own classes.

dataclass or TypedDict?

A dataclass is a real class with instance attributes, a constructor and equality — the right choice when you build objects in your own code.

A TypedDict describes a plain dictionary, which is what `json.loads` actually gives you. Choose it when you are annotating parsed JSON rather than constructing new objects, since it adds no runtime overhead at all.

Naming

Keys are converted to snake_case, which is what PEP 8 asks for. A key that is not a valid identifier — one starting with a digit, for instance — is prefixed with an underscore.

Note that this renaming means the generated types no longer match the JSON keys exactly. If you are parsing directly into them, use a library that supports field aliases.

Types come from one sample

Everything here is inferred from the JSON you paste. A field that happens to be absent from your example will be absent from the output, and a field that is null in the sample cannot be typed at all — only marked as nullable.

Paste the richest response you have, then review the optional and nullable fields by hand. Treat the result as a fast first draft rather than a schema.

Frequently asked questions

Can I get Pydantic models?

Not directly. A dataclass converts to a Pydantic model by swapping the import and decorator, which is a small edit.

Why is my null field typed so loosely?

Because a single null tells you nothing about what the field looks like when it is populated. It is marked nullable or optional so the code compiles, and it is the first thing worth correcting by hand.

Is my JSON uploaded?

No. The conversion runs in your browser, which matters when the sample you are pasting is a real API response with real customer data in it.