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.
Frequently Asked Questions
@dataclass vs pydantic — which should I pick?
Use pydantic when you need runtime validation, JSON parsing, and OpenAPI integration (e.g. FastAPI). Use @dataclass when you just need a typed container with no validation overhead.
Why TypedDict?
TypedDict is purely a typing construct — no runtime cost, no instance methods. Use it when you have existing code that passes around dicts and you want type-checker support without refactoring.
How are int vs float distinguished?
Number.isInteger checks the input: a whole number becomes int, a decimal becomes float. For decimal.Decimal precision, change manually after generation.
What happens to JSON keys with hyphens or spaces?
Snake_case conversion turns them into valid Python identifiers. For pydantic, the original key is preserved via Field(alias=...).
Does this send my JSON anywhere?
No. All generation happens locally in your browser.
Related Tools
JSON to Java Converter
Generate Java POJO classes from a JSON example. Infers types, creates nested classes, handles arrays as List<T>, and optionally uses Lombok @Data or full getters/setters.
JSON to TypeScript Interface
Convert any JSON object into TypeScript interfaces instantly — handles nested objects, arrays, union types, optional fields, and generics.
JSON to C# Converter
Generate C# classes from a JSON example. Infers types, creates nested classes, handles arrays as List<T>, and optionally emits [JsonPropertyName] attributes for System.Text.Json.
JSON to Dart Converter
Generate Dart classes from a JSON example. Includes nullable fields, fromJson factory constructors, and toJson methods for use with Flutter and Dart serialization.
JSON to Go Struct Converter
Generate Go structs from a JSON example. Infers types, creates nested structs, handles arrays as slices, and emits json:"..." struct tags ready for encoding/json.
JSON to Proto Converter
Generate a Protocol Buffers (proto3) schema from an example JSON object. Infers field types, creates nested messages, and handles arrays as repeated fields.

