CoreJSON

JSON to Python

This JSON to Python tool generates @dataclass definitions. You can choose Python 3.6–3.10 syntax (type annotations, built-in generics, PEP 604 union types) and field names are converted to snake_case automatically. Generation runs locally in your browser, suitable for both scripts and server-side development.

Open in the workbench Runs locally · nothing is uploaded

How to use it

  1. 1

    Paste your JSON

    Paste JSON data; nested objects produce related dataclasses and lists become List[T] annotations.

  2. 2

    Choose the Python version

    Python 3.10 uses X | None union syntax, while older versions fall back to Optional / Union.

  3. 3

    Copy the Python code

    Tick "Types only" for a pure dataclass, and pair it with dataclasses.asdict where useful.

  4. 4

    Use it in your code

    Import the dataclasses and construct them from parsed JSON dictionaries.

Key features

Native dataclass approach

Based on the standard-library dataclasses module with no third-party dependency, usable from Python 3.7 onward.

Version-adaptive syntax

Python 3.9 uses built-in list[int], 3.10 uses int | None, and older versions fall back to typing.List / Optional.

Snake_case conversion

camelCase and kebab-case keys are converted to the snake_case field names Python convention expects.

Optional full parsing code

When "Types only" is off, from_dict / to_dict helpers are added with nested objects constructed automatically.

Nested dataclasses

Nested objects generate their own dataclasses, so the type hierarchy is preserved.

Local and private

Generation runs in your browser and the data is not uploaded.

Common errors & troubleshooting

  • ! Python type annotations are not enforced at runtime, so dirty data can still be assigned; switch to a Pydantic model if you need validation.
  • ! A None field generates Optional[T], so check for None before deserialising.
  • ! A dictionary with free-form keys is not a good fit for a dataclass — keep it as dict[str, T] and handle it manually.
  • ! Turn on "Types only" when you want to paste the dataclasses into your own module without extra helpers.

Frequently asked questions

Is Pydantic supported?

The tool generates a standard-library dataclass (Pydantic v2 also supports dataclasses). A plain dataclass needs no extra dependency; for BaseModel runtime validation, replace @dataclass with pydantic.dataclasses.dataclass.

What does the Python version option affect?

3.10 allows int | None; from 3.9 list and dict can be used as generics directly; older versions output typing.List and typing.Optional. Choose according to your runtime environment.

Why do field names become snake_case?

PEP 8 recommends snake_case for variables and functions. The tool converts automatically, affecting only the Python-side field names, while the helper methods read and write using the original keys.

Is my data uploaded?

No. Generation runs locally in your browser.

Related tools