Convertful
ImagePDFVideoUtilityBlog

Image Tools

  • Compress Image
  • Resize Image
  • Remove Background
  • HEIC to JPG
  • All Image Tools →

PDF Tools

  • Compress PDF
  • Merge PDFs
  • Split PDF
  • PDF to Images
  • All PDF Tools →

Video & Audio

  • Video to GIF
  • Compress Video
  • Trim Video
  • Extract Audio
  • All Video Tools →

Utility

  • QR Code Generator
  • JSON Formatter
  • Color Converter
  • All Utility Tools →
All processing happens in your browser. Your files never leave your device.
AboutBlogTermsPrivacyContact
© 2026 Convertful. All rights reserved.
HomeUtilityJSON to Python Dataclass / TypedDict

JSON to Python Generator

Generate @dataclass or TypedDict classes from JSON. Free, private, runs in your browser.

100% private — your files never leave your browser. All processing happens locally on your device.

Settings

Paste JSON above to generate Python classes.

You might also need

JSON to TypeScriptGenerate TypeScript interfaces from a JSON sample
JSON to Go StructGenerate Go structs with JSON tags from a sample
JSON FormatterFormat and validate JSON data
JSON Diff CheckerCompare two JSON documents semantically

Dataclass Or TypedDict — Pick The Right Tool

Python has two idiomatic ways to model structured data with types. `@dataclass` (from `dataclasses`) gives you a real class with default values, `__init__`, `__repr__`, and equality — the right choice when the data is a first-class domain object you'll mutate, compose, and pass around. `TypedDict` (from `typing`) is a structural type hint for plain dictionaries — zero runtime overhead, still a plain `dict`, but your type checker now knows the keys and their types. Pick TypedDict when you receive JSON from an API and want typed access to a dict; pick dataclass when you want a real Python object.

Type Hints The Tool Emits

Strings become `str`, booleans become `bool`. Whole numbers become `int`, decimals become `float`. Null values in the sample emit `Optional[Any]` — a deliberate choice so the type hint doesn't pretend to know the shape of values that were never provided. Homogeneous arrays become `List[T]`; heterogeneous or empty arrays become `List[Any]`. Nested objects get their own class, referenced from the parent field.

Imports, Defaults, And Reserved Words

The output always starts with the appropriate imports — `dataclass` and `field` for dataclass mode, `TypedDict` for typeddict mode, plus `List`, `Optional`, `Any`, and `Dict` from typing. Dataclass fields get sensible defaults: `List` fields use `field(default_factory=list)`, `Dict` fields use `field(default_factory=dict)`, optionals default to `None`. Python reserved words (`class`, `for`, `import`, `return`, etc.) get a trailing underscore in the emitted field name to stay syntactically valid.

What You Might Tweak After Generation

Inference from a single sample has limits. If a field sometimes appears and sometimes doesn't, the emitted class won't know — mark that field `Optional[T]` manually. If two different sample responses have different types for the same field, you need a union (`Union[int, str]`) that one sample couldn't reveal. Use the output as scaffolding: 80-90% of the work is done, the remaining polish is intent you carry, not inference we can automate.

FAQ

What's the difference between dataclass and TypedDict?

A dataclass is a real class with default values, methods, and `__eq__`/`__repr__` auto-generated. A TypedDict is a structural type hint for plain dicts — it's compile-time-only and gives you mypy/pyright autocomplete without changing the underlying `dict` runtime shape.

Which should I pick?

For in-process data models and domain objects, pick dataclass — it's a real Python class with sensible defaults. For typing a JSON blob you receive from an API and want to keep as a plain dict, pick TypedDict.

Does it handle nested JSON?

Yes. Each unique nested object shape gets its own class, referenced from the parent field's type hint (e.g., `address: Address`). Identical shapes share a name; divergent shapes get numeric suffixes.

What about Python reserved words?

If a JSON key is a Python keyword (`class`, `for`, `import`, etc.), the emitted field appends a trailing underscore (`class_`) to stay valid.