JSON to Python Converter
Convert JSON data into Python dataclasses or plain typed classes. Infers types from values, handles nested objects, arrays, and optional fields, with optional to_dict/from_dict JSON helpers. Powered by quicktype-core.
Output will appear herequicktype-core, loaded on demand. Zero HTTP requests during generation — verify in DevTools' Network tab.About JSON to Python Converter
A JSON-to-Python generator infers Python type definitions — dataclasses by default — from sample JSON data, useful for typing API responses, configuration files, and external data sources in Python codebases. Uses quicktype-core (the open-source library that also powers app.quicktype.io and this site's JSON-to-TypeScript tool), which handles nested objects, arrays of mixed types, optional/nullable fields, and Pythonic snake_case naming. Output: `@dataclass`-decorated classes with full type hints, optionally paired with `from_dict`/`to_dict` helper methods for JSON (de)serialization — ready to paste into a Python 3.7+ codebase.
Why use a JSON to Python Converter?
Hand-writing Python type hints for a nested API response is slow and error-prone — it's easy to miss an optional field, mistype an attribute name, or fall back to `Any` for anything nested. Generating dataclasses from a real sample response is faster and self-updating: re-run the tool whenever the API changes shape. Useful for typing third-party REST/GraphQL responses, MongoDB or Firestore documents, YAML/JSON configuration files loaded at startup, and any JSON payload a Python service needs to consume with confidence instead of raw untyped dicts.
Who is it for?
Python developers integrating with REST or GraphQL APIs that ship no official SDK or type stubs, backend engineers writing FastAPI/Django/Flask response models, data engineers typing JSON documents pulled from NoSQL stores or message queues, and JavaScript/TypeScript developers who already use quicktype for json-to-typescript and want the equivalent Python output for a polyglot service.
How to use the tool
Paste a JSON sample into the input panel (a full API response, a single object, or an array of objects)
Set the 'Top-level class name' (default: Root) — this becomes the outermost dataclass name
Choose a Python version: 3.7+ for @dataclass with type hints, 3.6 for type-hinted plain classes, or 3.5 for untyped classes
Toggle 'Types only' off if you also want generated from_dict/to_dict helper methods for parsing and re-serializing the exact JSON shape
Review the generated Python in the output panel — every nested object becomes its own class, arrays get typed as List[...]
Check for Optional[...] fields and bare None types — these mark fields the tool wasn't fully certain about from a single sample
Copy the code with one click, or download it as a .py file
Paste multiple representative samples (as a JSON array) instead of one object for more accurate optional-field detection
Frequently Asked Questions
How do I convert JSON to Python dataclasses?
Paste a JSON sample (an API response, a config file, a single object) into the input panel. quicktype-core infers a type for every field — strings, ints, floats, booleans, nested objects, and typed lists — and emits one @dataclass-decorated class per object shape, plus a class for the top-level object named after your 'Top-level class name' field (default Root). By default the 'Types only' toggle is on, so you get clean dataclasses with nothing else. Turn it off to also generate from_dict/to_dict static and instance methods that parse and re-serialize the exact JSON shape you pasted, useful when you need real (de)serialization, not just editor autocomplete.
Dataclass vs Pydantic vs TypedDict — what's the difference, and which does this tool generate?
This tool generates Python dataclasses (@dataclass, from the standard-library dataclasses module) — plain, dependency-free classes with type-hinted attributes, available since Python 3.7. A TypedDict (typing.TypedDict) describes a plain dict's shape for static type checkers without creating a real class or runtime validation — the sibling json-schema-generator tool can produce those. Pydantic models add runtime validation, coercion, and JSON (de)serialization out of the box, but require the pydantic package. If your project already uses Pydantic, take this tool's dataclass output as a field-name/type reference and adapt it, or reach for Pydantic's own datamodel-code-generator.
Is my JSON sent to a server?
No — generation runs entirely in your browser. quicktype-core, the same open-source engine behind app.quicktype.io, is loaded on demand as a JavaScript module and executes locally; your JSON is never uploaded, logged, or stored. Verify it yourself in DevTools' Network tab: zero HTTP requests fire during conversion, and nothing persists after you close the tab. This makes it safe to experiment with realistic-looking payloads, though — as with any browser-based tool — scrubbing real production secrets, tokens, and personal data before pasting is still good hygiene, since clipboard history and screenshots can outlive the session.
Which Python version do I need — should I generate 3.5, 3.6, or 3.7+ code?
Pick the version matching your runtime. 3.7+ (the default) unlocks @dataclass, giving you an auto-generated __init__, __repr__, and __eq__ plus full type hints — the idiomatic choice for any codebase running Python 3.7 through current releases (dataclasses have been stable in this respect since their introduction). 3.6 emits the same type-hinted attributes but as a hand-written __init__ method, since the dataclasses module didn't exist yet. 3.5 drops type hints entirely, since PEP 526 variable annotations only landed in 3.6, producing plain untyped classes. Unless you're maintaining legacy infrastructure still on Python 3.5 or 3.6, leave this on 3.7+.
How are Optional / nullable fields inferred from my JSON sample?
The generator looks at every value it sees for a field. If a field is present in some objects — within an array of samples — but missing in others, it becomes Optional[X] = None. If the field's value is null in the sample you pasted, quicktype needs another type to union with None — but from a single sample where the value is always null, there's no other type to infer, so the field is typed as a bare None rather than a useful Optional[str]. This is the tool's main accuracy caveat: sample-based inference only knows what it has seen. Paste an array of several realistic objects, including edge cases with non-null values, for reliable Optional[...] typing.
Can I use this to generate typed models for a Python API client or backend?
Yes — paste a real (or representative) response body from the REST/GraphQL API you're integrating with, and the generator produces ready-to-use dataclasses for every nested resource: a User class, an Address class, and so on, wired together with type hints. This is the same workflow developers use quicktype for when writing a typed requests/httpx wrapper, a FastAPI response-model draft, or a Django/Flask serializer scaffold — generate once from a sample payload, then hand-tune field names, add validation, or convert to Pydantic if your framework expects it. It removes the tedious first draft of matching every JSON key to a Python attribute by hand.
Why are my camelCase JSON keys converted to snake_case in the output?
By default the generator applies Python's naming convention (PEP 8) to attribute names: a JSON key like createdAt becomes the dataclass attribute created_at, and isActive becomes is_active. The original JSON key is preserved for actual (de)serialization — when 'Types only' is switched off, the generated from_dict/to_dict methods read and write the original camelCase key (obj.get('createdAt')) while your Python code uses the snake_case attribute (self.created_at), so the mapping is never lost, it's just embedded in the helper methods rather than shown as a separate metadata block. With 'Types only' left on, only the class shape is emitted, since there's no parsing code that needs the raw key.
How does it handle nested objects and arrays with mixed-shape items? What about TypeScript instead?
Nested JSON objects become their own dataclasses automatically — an address object inside your top-level JSON gets its own Address class, referenced as a typed attribute on the parent. Arrays of primitives with mixed types, like [1, "two", true], become List[Union[int, str, bool]]. Arrays of objects with different shapes are merged into a single class covering every field seen across all items, with fields absent from some items marked Optional — a simpler model than a true per-shape tagged union, so verify it against your real data if items vary a lot. Need TypeScript instead of Python? Use the sibling json-to-typescript tool; need a portable JSON Schema first, try json-schema-generator.
Share This Tool
Found this tool helpful? Share it with others who might benefit from it!
💡 Help others discover useful tools! Sharing helps us keep these tools free and accessible to everyone.