JSON to PythonONLINE

Generate Python types or models from sample JSON and download .py code.

1 MiB per input · Ctrl / ⌘ + Enter to run

quicktype infers shapes from a sample up to 128 Ki characters. Review field optionality, names, and type choices before adding generated code to your project.

Result
Ready. Paste input, then run the tool.
Your JSON stays in your browser. Core processing happens locally.
THE PRACTICAL GUIDE

Generate Python data models from sample JSON

JSON to Python generates a starting Python data model from a JSON example. It saves manual transcription of nested keys and observed value types.

When should you use it?

  • Sketch Python classes for an API response.
  • Document nested fixture data in a Python project.
  • Compare observed fields before writing a parser.
WORKED EXAMPLE

Example: infer Python fields from JSON

This abbreviated example shows the inferred name and active fields in Python. The full generated file includes imports and helpers and may change with generator versions; review it before adding it to a project.

Sample JSON
{"name":"Alex","active":true}
Illustrative model excerpt
@dataclass
class Root:
    name: str
    active: bool

Use the sample to draft the model shape

Nested dictionaries and lists become candidates for named models and collection fields. This is useful when moving from ad hoc dictionary access toward a clearer API client. Python type hints describe intended values, but enforcement depends on the generated loading code and the validation approach your application uses. Read those helpers along with the class definitions.

Decide how absent values should behave

A missing field, null, and an empty string have different meanings. Check the inferred optional fields and defaults against real responses. Also review date-like strings and numeric fields rather than assuming that every convenient inference matches the domain. Run the generated code with representative valid and invalid fixtures in your own Python environment before using it as an application boundary.

IN PRACTICE

How do I create Python data classes from JSON API data?

Generate Python code from a representative sample, then inspect the inferred fields and conversion functions. quicktype’s Python target can produce a dataclass-style model, which gives a useful first draft for nested records.

Illustrative Python data model

python
from dataclasses import dataclass

@dataclass
class Root:
    name: str
    active: bool

The complete .py output includes helpers and imports. Check null handling and the Python version used by your application.

The generator only sees the supplied example. Include realistic variants and edit the model for fields that are optional, conditionally present, or absent from this sample.

BEFORE YOU USE THE RESULT

What should you check before using the result?

Generated code reflects one sample, not a guaranteed API contract. Review naming, imports, optional fields, conversion behavior, and your project’s Python version before use.

Understand JSON syntax

Technical reference: quicktype model generation documentation

THE JSON FIELD GUIDE
All guides