JSON to Python dataclass
Turn a JSON sample into typed Python classes — dataclass, Pydantic, TypedDict or NamedTuple.
JSON to Python dataclass
Paste a JSON object or array and this tool infers types for every field and generates Python classes with full type annotations. Choose the output style that fits your codebase: @dataclass, Pydantic BaseModel for validation, TypedDict for existing dict-based code, or NamedTuple for immutable records. Nested objects become their own classes in the right order so the file runs as-is; identical objects reuse a single class instead of duplicating.
Options control how conservative or modern the code is. "Optional for null fields" converts null values to Optional types instead of bare None; "Add default values" enables omitting fields when constructing instances with automatic reordering. "Alias invalid field names" sanitizes JSON keys that aren't Python identifiers, preserving the original key through field metadata or Pydantic Field(alias=...) for correct serialization. "list[T] instead of List[T]" switches between modern PEP 585 builtins and older typing.List, while __future__ annotations changes to X | None / X | Y syntax.
Type inference distinguishes strings, integers, floats and booleans, merges mixed array contents into Union types, and gives root arrays a RootItem class with a Root = list[RootItem] alias. Whole numbers without decimals are read as int—there's no way to recover a decimal "36.0" after parsing. Everything runs locally in your browser; your JSON and generated Python never leave your device.