DT Dev Tools

JSON to Python Class Generator

Convert JSON to Python dataclasses or Pydantic models with type hints, snake_case fields and from_dict/to_dict helpers. Free, private and runs in your browser.

πŸ”’ Runs entirely in your browser β€” nothing is uploaded

Advertisement

From JSON to typed Python classes

Working with raw dictionaries is quick until a typo in a key name causes a KeyError three layers deep. This JSON to Python converter generates typed classes from a JSON sample so your editor, type checker and teammates know exactly what each payload contains. Each object becomes a class with annotated attributes, nested objects become their own classes, lists are typed by their element type, and values that are sometimes absent are typed as optional. JSON keys are converted to snake_case attribute names, while the generated serialization code keeps the original keys on the wire.

Generation is handled by quicktype, which merges all elements of every array before inferring types, so a field that only appears in some items is still captured and marked optional rather than silently dropped.

Dataclasses, Pydantic and Python versions

By default the output uses standard-library @dataclass classes plus from_dict and to_dict functions that validate and convert each field, so you need no third-party dependency. If your project already uses Pydantic β€” for FastAPI request bodies, settings or validation β€” tick Pydantic BaseModel and the classes inherit from BaseModel instead. The Python version selector controls typing syntax: 3.10+ produces modern list[int] and str | None annotations, while older targets fall back to the typing module. Tick Classes only to skip the conversion helpers entirely.

Practical tips

Use a sample that exercises optional fields and contains several array elements, since inference can only describe what it sees. Name the root class after your domain β€” Invoice reads better than Root β€” and the download will use that name. After generating, run your formatter and type checker (Black, Ruff, mypy or Pyright) and tighten anything the sample could not reveal, such as strings that are really enums or numbers that should be Decimal. All parsing and code generation happen locally, so you can safely paste responses that contain customer data.

How to use

  1. Paste JSONPaste a JSON object or array, or click Load sample.
  2. Choose a stylePick your Python version and whether you want dataclasses or Pydantic models.
  3. Copy the classesCopy the generated code or download it as a .py module.

Frequently asked questions

Does it generate dataclasses or Pydantic models?
Both. The default output uses @dataclass with type hints; tick Pydantic BaseModel to get Pydantic models instead.
Which Python versions are supported?
Choose 3.6, 3.7, 3.9 or 3.10+. Newer targets use built-in generics like list[str] and the X | None union syntax.
Are property names converted to snake_case?
Yes. Field names become Pythonic snake_case while the generated from_dict and to_dict functions keep the original JSON keys.
Is my data uploaded?
No. Everything runs locally in your browser, so private API responses stay on your device.
Advertisement