Code Generators · Runs in your browser

JSON to Python Dataclass & Pydantic Generator

Paste a JSON sample and get ready-to-use Python classes, with nested types, arrays and optional fields worked out for you. Ideal for typed models in FastAPI, requests or data pipelines.

JSON
Drop a file to load it
Python
Waiting for input

How to use it

  1. Paste a representative JSON sample, such as an API response.
  2. Set the root type name and pick a style: dataclasses, Pydantic models or TypedDict.
  3. Copy the Python code or download it as a file.

Pydantic aliases

Keys that aren’t valid Python names (user-name, class) become snake_case fields with an alias, so the model still validates the original JSON.

Order

Nested classes are written before the classes that use them, so the file runs without forward-reference errors.

Integers vs. decimals

Number types come from how the number is written in your sample: 3 is an integer, 3.0 and 3.5 are decimals, and long IDs use a 64-bit type.