JSON Parser

JSON to Python Dataclass Converter Online

Paste any JSON and get ready-to-use Python types in one click. Nested objects, arrays, optional fields and awkward key names are handled for you, and everything runs in your browser, so API responses and sample payloads are never uploaded.

How to convert JSON to Python

  1. Paste your JSON, or click Upload to load a file. Use a sample that includes every field, since the types are inferred from it.
  2. Set the Root class name if you want something other than Root.
  3. Review the output on the right and click Copy.

Example

JSON input

{
  "id": 1,
  "name": "Alice",
  "active": true,
  "score": 98.5,
  "tags": ["admin"],
  "address": { "city": "New York" }
}

Python output

from __future__ import annotations
from dataclasses import dataclass
from typing import List


@dataclass
class Root:
    id: int
    name: str
    active: bool
    score: float
    tags: List[str]
    address: Address


@dataclass
class Address:
    city: str

JSON to Python type mapping

JSONPython
stringstr
whole numberint
decimal numberfloat
booleanbool
arrayList[T]
objecta @dataclass
null / unknownAny

Naming and structure

Field names keep the original key when it is a valid Python identifier; otherwise they become snake_case with a comment showing the original key. Required fields are listed first, because dataclass fields with defaults must come last.

  • Fields that are null or missing in some items become Optional[T] = None.
  • The output includes from __future__ import annotations, so classes can reference each other regardless of order.
  • When an array contains objects, their fields are merged: a field missing from some items is treated as optional, and a field that is a whole number in one item and a decimal in another becomes a decimal.
  • The top-level JSON can be an object or an array of objects.

Using the generated types

import json
root = Root(**json.loads(text))   # flat objects
# nested data: use dacite or pydantic to build the nested dataclasses

Related tools

Describe the same data with the JSON Schema generator, get TypeScript interfaces, create a SQL table, fix broken input with JSON Repair, or compare payloads with JSON Diff.

Frequently asked questions

How do I convert JSON to Python classes?
Paste your JSON and copy the generated code. Objects become @dataclass classes, arrays become List[T], and fields that are null or missing in some items become Optional[T] = None.
Why are required fields listed before optional ones?
Python dataclasses require fields without defaults to come before fields with defaults, so the generator sorts required fields first and puts Optional fields (default None) last.
How do I load JSON into the generated classes?
For flat objects use Root(**json.loads(text)). For nested data, use a library such as dacite or pydantic to build the nested dataclasses from a dict. Keys that are not valid Python identifiers are renamed to snake_case with a comment showing the original key. Everything runs in your browser — your JSON is never uploaded to a server.
Handles JSON files up to 20MB smoothly