JSON to Python Class Generator

Create dataclasses, Pydantic models or TypedDicts from example JSON.

100% Client-Side Processing — your data never leaves this browser. Works offline. How it works

0 lines • 0 bytes Ready
Tip: drop a file anywhere on the editor
Input
Paste, type or drop a file
1
Result
Updates as you type
// Output will appear here…
About this tool

How the JSON to Python Class works

Generate Python dataclasses, Pydantic models or TypedDicts from JSON. Snake_case fields, aliases for camelCase keys, optional fields and nested classes.

How to use the JSON to Python Class

  1. Paste JSON.
  2. Choose dataclass, Pydantic model or TypedDict and set the root class name.
  3. Copy the classes into your project.

JSON to Python Class example

Input
{"id":7,"userName":"aarav","tags":["a"],"address":{"city":"Pune"}}
Result
from dataclasses import dataclass


@dataclass
class Address:
    city: str


@dataclass
class User:
    id: int
    user_name: str
    tags: list[str]
    address: Address

When to use it

  • Typing API clients and webhook payloads.
  • Defining FastAPI request and response models.
  • Adding type hints to scripts that load JSON.

Tip: Choose Pydantic when you need validation and alias handling; it parses camelCase keys into snake_case fields for you.

Three styles

Standard-library dataclasses, Pydantic BaseModel with aliases, or TypedDict for type-checking plain dicts.

Pythonic names

camelCase keys become snake_case fields; Pydantic keeps the original key as an alias.

Nested classes

Nested objects become their own classes, defined before the classes that use them.

Optional fields

Missing or null values become X | None with a None default, placed after required fields.

FAQ

Common questions

Which Python version is needed?

Python 3.10 or later, because the output uses list[str] and X | None.

How are keys that are not valid names handled?

Fields are renamed (class → class_, 2fa → field_2fa). TypedDict switches to the functional syntax so the real keys are kept.

Are dates converted?

With Pydantic, ISO date strings are typed as datetime or date and parsed automatically. Dataclasses and TypedDict keep str, because json.loads returns strings.

Is my JSON private?

Yes, the code is generated in your browser.