JSON to Python dataclass

Generate Python dataclasses with type hints from a sample JSON document.

Converted in this browser. Nothing is sent anywhere.

Objects become @dataclass classes, arrays become list[...], fields missing in some array elements become Optional[...] = None. Keys that are not valid Python identifiers are renamed with the original key in a comment.

How to use

  1. Paste a JSON sample.
  2. Name the root class.
  3. Copy the generated Python code.

What it supports

Objects become nested @dataclass definitions; Optional marks nullable fields; lists infer the merged element type. Keys become snake_case fields; a comment keeps the original key when it differs. Input up to 2 MB, nesting to 40 levels.

Related tools

Related guides