~/json-to-types

JSON to Python dataclass generator

Convert any JSON sample to a Python dataclass with type hints. Includes optional from_dict / to_dict converters. Runs entirely in your browser.

# context

Python 3.7+ dataclasses give you typed model classes with automatic `__init__`, `__repr__`, and `__eq__`. Pair with a JSON parser and you have a typed API client. This tool emits the dataclass plus from/to-dict helpers that handle the parsing.

JSON input

{
  "id": 1,
  "name": "Ada Lovelace",
  "email": "[email protected]",
  "active": true,
  "roles": ["admin", "engineer"],
  "createdAt": "2026-05-14T00:00:00Z"
}

Output preview

from dataclasses import dataclass
from typing import List

@dataclass
class User:
    id: int
    name: str
    email: str
    active: bool
    roles: List[str]
    created_at: str

    @staticmethod
    def from_dict(obj: dict) -> 'User':
        return User(
            id=obj["id"],
            name=obj["name"],
            email=obj["email"],
            active=obj["active"],
            roles=obj["roles"],
            created_at=obj["createdAt"],
        )

→ Open in JSON to Types generator (pre-filled)

# notes

# other targets