JSON to Python Dataclasses
Paste a JSON sample and get ready-to-paste Python type definitions. Objects become @dataclass classes (or TypedDict subclasses when you prefer maps), arrays become lists of the inferred element type, numbers become int or float, and nulls or optionally-typed fields get sensible defaults. Nested objects are hoisted into their own named models, keys can be snake_cased, and the output is import-clean for modern Python. All inference runs on your device.
🔒 100% Client-Side & Private — processed locally in your browser. Files never leave your device.
Options
Your result will appear here
Type or paste your input above, adjust the options, then press Run. Tip: press Ctrl+Enter to run, and ? for every shortcut.
How it works
What it returns
Input is one JSON value as text, up to 1,000,000 characters; the output is a Python module — imports, then one class per shape. Objects are walked depth-first into named models, arrays become list[Element], whole numbers int, fractional numbers float, booleans bool and strings str. Only the first array element is sampled, so a mixed array collapses to the type of that entry.
When the sample comes from an API contract
When you hold a representative response body and want typed models before writing any parsing code, paste it and take the generated classes straight into the project. Dataclass is the default style; choose TypedDict when your codebase prefers mapping-style types.
The options that change the output
style picks @dataclass or TypedDict. snakeCase rewrites camelCase keys to snake_case field names — switch it off to keep the JSON key verbatim. useOptional annotates non-list fields as optional and defaults them from the sample, and unionSyntax chooses Optional[str] or str | None. indent accepts 2, 3, 4, 6 or 8 spaces; any other value is rejected.
Guessed types, gaps and privacy
A JSON null always becomes Optional[Any] = None rather than a concrete type, empty arrays become list[Any], and keys that would not be valid Python identifiers are prefixed so the module still parses. The conversion is a pure function in this tab: JavaScript parses and emits everything on this device, nothing is uploaded and nothing survives the page.
Questions
Which Python version is the output for?
The generated module uses from __future__ import annotations and built-in generics (list[x], dict[str, x]), so it is compatible with Python 3.9+. The "str | None" union style needs 3.10+; Optional[str] is the safe default.
How are arrays handled?
Arrays become list[Element]. If the element is an object, a new model is generated (or reused) and the field is list[ThatModel].
What about recursive or repeated shapes?
Each distinct nested shape is emitted exactly once, named after its key, and later uses reference the same model. If a model would recurse, the forward reference stays valid thanks to the postponed annotations import.
Is this a full schema?
No — it is a type-guessing tool like the rest of the JSON family. Edge cases such as genuinely mixed-type arrays or optional fields missing from the sample are inferred optimistically, so review the output.
Related tools
See categoryJSON to TypeScript
Generate TypeScript interfaces or type aliases from a JSON sample, with nested named types.
JSON to Go Struct
Generate idiomatic Go structs with json tags from a JSON sample, ready for encoding/json round-trips.
JSON to Zod Schema
Generate a Zod schema from a JSON sample so you can validate runtime data and infer clean types.
JSON to JSON Schema
Infer a JSON Schema (draft 2020-12) from a JSON sample, with required and additionalProperties control.