IQ
PayloadIQ
PayloadIQ Utilities

JSON to Python

Paste a JSON sample and get typed Python back — dataclasses, Pydantic models, TypedDicts, or a dict literal. Nested objects and arrays are inferred, and it all runs in your browser.

Python classes appear here.

Runs in your browser. Your input is not uploaded to PayloadIQ.

JSON to Python converts a JSON sample into Python source you can paste straight into a model file — choose dataclasses, Pydantic v2 models, TypedDicts, or a plain dict literal. The structure is inferred from your example: nested objects become nested classes, arrays become List[...], and nulls become Optional[...]. Everything happens locally in your browser, so a real API response never leaves your machine.

dataclasses, Pydantic, or TypedDict — your call

Reach for dataclasses when you want zero dependencies and plain typed containers, Pydantic when you want runtime validation and parsing of the incoming payload, and TypedDict when you keep the data as dicts but still want editor and type-checker support. The dict-literal mode is handy for fixtures, test data, and quick scripts.

From a payload to a typed model

Inference is sample-driven, so paste the richest payload you have — for lists of objects it merges the keys across elements and marks any that are missing as optional. Want types in another language, or a full typed client and schema report from the same payload? Open it in the PayloadIQ playground or read the JSON to TypeScript guide.

FAQ

Is my JSON uploaded?
No. The JSON is parsed and converted entirely in your browser with JavaScript — it never leaves your device. That makes it safe for real API responses, auth payloads, and anything internal.
Which Python outputs are supported?
Four: standard library dataclasses, Pydantic v2 BaseModel classes, typing.TypedDict classes, and a plain Python dict literal (with True/False/None). Switch between them with the Output selector.
How are the types inferred?
From your sample. Nested objects become their own nested classes, arrays become List[...] (with the element type inferred), and a null value becomes Optional[...]. Inference is only as complete as the sample, so paste a representative payload — for arrays it merges keys across elements and marks missing ones Optional.
What about keys that aren't valid Python identifiers?
They're sanitized to valid names (for example a hyphen becomes an underscore). For Pydantic the original is preserved as Field(alias="..."); for dataclasses and TypedDict the original JSON key is kept in a comment.

Related utilities

cURL to CodeJSON Formatter / ValidatorJSON to YAMLGuide: JSON to TypeScript
Open PayloadIQ Playground