100% Local — never leaves your browser

JSON to Python Converter

Convert a JSON object into Python dataclasses instantly in your browser, with types inferred automatically.

JSON Input
Python Output
Ad slot

How to use this tool

Writing dataclass definitions by hand to match an API response or config file is tedious and easy to get subtly wrong — especially remembering that Python requires every required field to come before any field with a default value. This tool reads a JSON sample and generates matching Python @dataclass definitions automatically — inferring str, int, float, bool, List, and Optional types, and splitting nested objects into their own named classes rather than one giant nested structure.

For example, {"name": "Alice", "address": {"city": "NYC"}} generates:

from dataclasses import dataclass


@dataclass
class Address:
    city: str


@dataclass
class Root:
    name: str
    address: Address

Paste your JSON into the input box on the left, set the Class name you want for the top-level type, and click Convert. The generated Python appears in the output box on the right, with any parse errors shown below.

FAQ

Is this JSON to Python converter free to use?

Yes, this tool is completely free to use with no limits on how often you can use it.

Does my JSON get uploaded anywhere?

No. The dataclasses are generated directly in your browser. Your data never leaves your computer.

How does it handle arrays of objects with slightly different fields?

It merges the shapes of every object in the array into a single dataclass. A field present in only some elements — or that's null in some of them — becomes Optional with a default of None, rather than being dropped or causing an error. Required fields are always listed before optional ones, since Python requires that ordering in a dataclass.

Why do some number fields come out as float instead of int?

If every sample of a field is a whole number, it's typed int. If any sample has a decimal point, it's typed float — and if a field mixes both across samples, the whole field is typed float rather than a Union, since Python's own typing rules already treat int as valid wherever float is expected.

What happens to JSON keys that aren't valid Python identifiers?

Keys with characters Python doesn't allow in a name (like hyphens or a leading digit) are converted to a safe equivalent — "foo-bar" becomes foo_bar, for example. This means constructing an instance directly from the original JSON dict (MyClass(**data)) won't work for those specific fields unless you rename the keys first to match; every other field, which is the common case, round-trips normally.

Related Tools