JSON to Python Converter
Paste a JSON object and get Python classes — @dataclass, pydantic BaseModel, TypedDict, or attrs — with typed fields, nested classes, and snake_case naming.
Last updated: May 27, 2026
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat is JSON to Python Converter?
Modern Python has four mainstream ways to declare a data class: stdlib's `@dataclass`, the third-party `pydantic` (popular for runtime validation), `TypedDict` (purely a type hint, no runtime cost), and `attrs` (`@attrs.define`). Each fits a different use case — pydantic for API I/O, dataclass for value objects, TypedDict for typing existing dicts.
This tool generates the same field structure in any of those styles. It converts JSON keys to snake_case (Python convention), infers `int` vs `float` from the value, recognizes nested objects as nested classes, and uses `list[T]` (Python 3.10+) or `List[T]` (3.9 fallback) for arrays. The pydantic output adds `Field(alias="...")` when the JSON key cannot be a valid Python identifier.
How to Use JSON to Python Converter
Paste a JSON object (root must be an object).
Pick a style: @dataclass, pydantic, TypedDict, or @attrs.define.
Pick a Python version: 3.10+ for modern syntax or 3.9 for typing-module imports.
Toggle "Make all fields Optional" if any JSON key may be missing.
Copy the generated Python code into your project.
Common Use Cases
- Bootstrapping pydantic models for a FastAPI service.
- Generating @dataclass types for a Python CLI consuming JSON.
- Producing TypedDict definitions to add types to existing dict-based code.
- Translating an OpenAPI example into Python types.
Example Input and Output
A flat JSON object generates a @dataclass with snake_case fields.
{ "userId": 42, "name": "Alice", "active": true }from dataclasses import dataclass
@dataclass
class Root:
user_id: int
name: str
active: boolPrivacy
All conversion happens in your browser. No JSON is sent to a server.
Class ordering
Nested classes are emitted before the classes that reference them, so the file can be read top-to-bottom without forward references.
Python 3.9 typing imports
On Python 3.9 the tool emits List[T] and Optional[X] from the typing module. On 3.10+ it uses the built-in list[T] and X | None which need no imports.

