JSON to Python Dataclasses
Generate Python dataclasses (or TypedDicts, or Pydantic models) from JSON. Pick the target library and download a ready-to-import module.
Output will appear here…Generate typed Python classes from JSON
Python has three common ways to represent structured data with types: dataclasses (in the standard library since Python 3.7), TypedDict (for typing dict-based code without changing the runtime behavior), and Pydantic (for runtime validation and serialization). Lintify can generate any of the three from a sample JSON document — pick the one that matches your use case.
Dataclasses are the right default for most code. They are in the standard library, work everywhere with no extra dependencies, and integrate cleanly with type checkers. Pydantic is the right pick for API code where you need to validate input at runtime — it gives you validation, serialization, and JSON Schema generation for free. TypedDict is useful when you have existing dict-based code that you want to type without rewriting.
How JSON types map to Python types
JSON strings become str, numbers becomeint or float depending on whether they have a decimal part, booleans becomebool, and null becomesNone (with the field markedOptional[T] in dataclass and Pydantic mode). Arrays become list[T] where T is inferred from the first element. Objects become a new class.
Optional fields with arrays of mixed shapes
When you paste a JSON array, the generator merges the keys of every object. Any key that is missing from at least one element is marked Optional[T] — the field can be None at runtime. This matches what real API responses look like, where some fields are nullable or omitted in certain conditions. For a single object, every field is required because there is no comparison sample.
Class naming and nesting
Each nested JSON object becomes a class named after its parent key, in PascalCase. For example,users[0].address becomes a class namedAddress. The class names are unique within the module, so collisions are resolved by appending a numeric suffix. The output uses Python 3.9+ syntax (list, dict, tuple) rather than the older typing.List imports — add from __future__ import annotations if you need to support older Python.
Frequently asked questions
Common questions about the JSON → Python tool.