Skip to main content

JSON to Python Class Converter

Paste any JSON and get production-ready Python classes instantly: dataclasses, Pydantic v2 models, attrs classes, or TypedDicts. Smart type inference turns nested objects into nested classes, arrays into List[T], nulls into Optional fields, and ISO-8601 strings into datetime — live, in your browser, with zero uploads.

100% client-side4 output stylesNo signupFree forever
Output style:
Root class:

JSON input

Ctrl/⌘+Enter converts · drag & drop a .json file or use upload.

Python output

Classes: 0Fields: 0Lines: 0

How to convert JSON to Python classes

1

Paste or upload JSON

Drop your JSON into the input box, upload a .json file, or start from a sample. Conversion to Python classes starts live as you type.

2

Pick a class style

Choose dataclasses, Pydantic v2, attrs, or TypedDict. Tune the root class name, snake_case naming, Optional fields, and datetime detection.

3

Copy or download

Copy the generated code to your clipboard or download it as a .py file, ready to drop into any Python 3 project.

JSON to Python type mapping

Every JSON value is mapped to the most precise Python type the sample supports. Arrays of objects are merged across all items, so a key that appears in only some items becomes Optional.

JSON valuePython typeNotes
stringstrISO-8601 strings become datetime/date when detection is on
integerintint + float mixes widen to float
numberfloat 
booleanbool 
nullOptional[Any]or Optional[T] when siblings carry values
arrayList[T]empty arrays become List[Any]; mixed arrays become Union
objectNestedClassemitted before its parent; uniform flat objects can become Dict[str, T]

JSON to Python converter FAQ

What does a JSON to Python class converter do?

It reads a JSON document and writes the equivalent Python classes for you, with correct type hints. Paste an API response and you get ready-to-use dataclasses, Pydantic v2 models, attrs classes, or TypedDicts — including nested classes for nested objects, List[T] for arrays, and Optional for fields that can be null.

How do I convert JSON to a Python dataclass online?

Paste your JSON into the input panel, drop a .json file onto it, or start from a sample — the dataclass output updates live as you type. Set the root class name if you like, then copy the code or download it as a .py file. Nothing is uploaded; the conversion runs entirely in your browser.

Which Python class styles can it generate?

Four styles: stdlib dataclasses (the default), Pydantic v2 BaseModel with Field aliases, attrs @define classes, and TypedDict with NotRequired for optional keys. Switch styles with one click and the imports, decorators, and defaults are rewritten for that style.

How are nested JSON objects handled?

Every nested object becomes its own Python class, emitted before the class that uses it, so the generated file is valid top to bottom. Arrays of objects are merged by key: if one item has an email field and another does not, the merged class marks that field Optional.

How does the tool type null values and missing keys?

A JSON null becomes Optional[Any], or Optional of the merged type when sibling items carry real values; a key missing from some array items is marked Optional with a None default. Turn off the "Optional for nullable fields" option if you would rather have bare types.

Can it detect dates and datetimes inside JSON strings?

Yes. ISO-8601 strings such as 2026-10-08T14:30:00Z become datetime and plain 1999-05-01 dates become date, with the matching from datetime import added automatically. Strings that merely look date-like but are invalid stay str, and detection can be switched off.

How are JSON arrays converted to Python types?

Arrays become List[T] with T inferred from the items: List[str], List[int], or List[SomeClass] for arrays of objects. Mixed-type arrays become Union types, empty arrays become List[Any], and objects whose values all share one primitive type can be emitted as Dict[str, T] instead of a class.

Does it convert camelCase JSON keys to snake_case?

Yes, by default userName becomes user_name, Python keywords such as class become class_, and keys starting with digits are prefixed. In Pydantic v2 mode the original JSON key is preserved as Field(alias="userName") with populate_by_name enabled, so parsing the raw JSON still works.

Is my JSON data sent to a server?

No. The JSON parser and the Python code generator are 100% client-side JavaScript with zero external requests. Your data never leaves the browser tab, which makes this converter safe for API responses that contain real user data.

Is this JSON to Python converter free?

Yes — free with no signup, no usage limits, and no watermarks. Generate dataclasses, Pydantic models, attrs classes, or TypedDicts and download the .py file as often as you like.

Free tool by NRTechStudio