JSON to Python
JSON → pydantic / dataclass
from typing import Any, List, Optional, Union, TypedDict
class User(TypedDict, total=False):
id: float
name: str
active: bool
tags: List[str]
class Post(TypedDict, total=False):
id: float
title: str
pinned: Optional[bool]
class Root(TypedDict, total=False):
user: User
posts: List[Post]TypedDict shapes (Python 3.8+). JSON numbers map to float; coerce to int manually if needed.What is JSON to Python?
Infer Python TypedDict classes from a sample JSON object, with proper handling of optional keys, nested dictionaries, and list element types. Useful for integrating an external API into a Python codebase with proper type hints, or generating starter stubs for a new service.
How do I use JSON to Python?
- Paste sample JSON.
- Set the root class name.
- Copy or download the generated Python.
When should I use JSON to Python?
JSON to Python emits TypedDict. For dataclass / attrs / pydantic output, pydantic-specifically has its own generator; we emit the lightest option. For TypeScript types instead, use JSON to TS.
Does it generate dataclasses or plain dicts?
Dataclasses by default (with type hints for mypy / pyright). Switch to TypedDict for dict-based APIs, or Pydantic for validation-first workflows.
Does it handle optional fields correctly?
Yes — fields that are missing or null in any object become Optional[...] with a default of None.
What Python version does the output target?
Python 3.10+ style by default (union X | Y, from __future__ import annotations). Toggle 3.8 compatibility to get Optional[X] and Union[X, Y] instead.
Is my file uploaded anywhere?
No. Everything runs in your browser. Your files never leave your device, and there is no server component for this tool.