Dev Tools

JSON → Python Dataclass

Generate Python dataclass code from JSON. Includes @dataclass decorator, type hints, and handles nested objects.

Root class name
JSON input
Python output
from dataclasses import dataclass
from typing import List, Optional, Any


@dataclass
class Address:
    street: str
    city: str
    zip: str


@dataclass
class Order:
    id: int
    total: float
    items: List[str]


@dataclass
class Root:
    id: int
    name: str
    email: str
    active: bool
    score: float
    address: Address
    tags: List[str]
    orders: List[Order]
    metadata: Optional[Any]
Was this page helpful?

Related tools