/tools/json-to-python

JSON to Python Converter

Generate Python 3.10+ Pydantic v2 models, keyword-only dataclasses or precise TypedDict definitions.

json-to-python://local

JSON sample

Python output

Ready. Paste representative JSON to infer Python models locally.

/usage

Generate Python models from real JSON

  1. Paste a representative API response or choose a JSON file.
  2. Select Pydantic v2, dataclasses or TypedDict output and name the root model.
  3. Generate, review uncertain unions or empty arrays, then copy or download the Python file.

/inference

Python output that preserves the evidence

Pydantic v2 by default

Renamed fields use aliases and ConfigDict(populate_by_name=True), so awkward JSON keys remain serialisation-safe.

Missing differs from null

Fields missing from some array objects become optional. Explicit JSON nulls remain visible in the generated type.

Alternative standard-library shapes

Keyword-only dataclasses and TypedDict output support projects that do not use Pydantic.

Bounded local work

The shared inference worker records shape evidence rather than duplicate values, with depth, traversal, schema and output limits.

/faq

JSON to Python questions

Does it support nested arrays and objects?

Yes. Every sampled array item contributes evidence to deterministic nested models.

Why does an empty array use Any?

An empty array contains no element evidence. Add a representative item or replace Any with the domain type after generation.

Is generated code a finished domain model?

It is a strong starting contract from observed data. Review semantic constraints, validators and domain naming before production use.