JSON to Python Dataclass
Generate Python dataclasses or Pydantic models from sample JSON. Review nested types, field aliases and optional defaults.
Model JSON with Dataclasses or Pydantic
Leave the pointer blank to use the full document. Use /items or /items/0 to pick a nested value.
JSON to Python Dataclass: how to use it
- Paste JSON, open a local UTF-8 file or load the inventory example. Enter a model name and optionally select a nested root with a JSON Pointer.
- Choose a standard library dataclass, Pydantic v1 or Pydantic v2. Set the default policy for fields that are missing or carry null.
- Generate Python. Review snake_case names, original JSON keys, unions and defaults, then download models.py or copy the code.
Limits and notes
Uses up to 4,194,304 input and output characters, a 4 MiB UTF-8 file, 128 nested levels and 500,000 JSON tokens. Duplicate keys are rejected. Processing stays on this device.
How your privacy works →JSON to Python Dataclass: common questions
How are camelCase or hyphenated JSON keys handled?
The generator uses Python-safe snake_case attributes. Dataclasses keep original keys as field metadata and Pydantic models use field aliases.
Does Optional mean a constructor field has a default?
Optional[T] allows None in the annotation. A field with no default can still be required. The default setting separately controls whether a field may be omitted.
How do arrays at the document root become Python types?
A root array becomes a List alias. Named classes model its object items. Use a Pydantic v2 TypeAdapter or a Pydantic v1 parse_obj_as call when validating the full array.