JSON to Python Converter
from __future__ import annotations
from dataclasses import dataclass
from typing import Any, Optional
@dataclass
class Profile:
bio: Optional[Any]
website: str
@dataclass
class Post:
title: str
views: int
pinned: Optional[bool] = None
@dataclass
class AutoGenerated:
id: int
name: str
active: bool
score: float
roles: list[str]
profile: Profile
posts: list[Post]Turn a JSON sample into Python classes
Paste an example API response or config object and get Python class definitions to model it. Choose @dataclass classes or Pydantic v2 BaseModel classes. Nested objects become their own named classes, arrays of objects are merged into one element class where keys missing from some items become Optional[...] with a = None default, empty or mixed arrays become list[Any], and the top-level class is named AutoGenerated. Dependency classes are emitted before the classes that use them so the output runs as-is.
When to use this tool
Use it to scaffold Python models from a sample payload — paste an API response, fixture, or config object and get dataclass or Pydantic v2 classes to load it into for FastAPI, validation, or data pipelines.
Privacy and limitations
Conversion runs locally in your browser with JSON.parse, so payloads never leave the page. Types are inferred from one sample: Optional fields, list element types, and class names reflect only the values you paste, so review them before committing.