JSON to Python

  • Dataclass
  • TypedDict
  • Instant

Dataclasses or TypedDicts, with Optional where the sample is inconsistent.

Input
Python

Paste input on the left to see python.

Everything runs in your browser — nothing is uploaded.

About python

Generating Python types from JSON produces dataclasses or TypedDicts. JSONic converts field names to snake_case and keeps the original key in a comment, and marks keys absent from some array elements as Optional with a None default so the generated class stays constructible.

Paste JSON and get Python type definitions. Dataclasses give you runtime objects with constructors; TypedDicts describe the dict shape without changing how you access it, which suits code that already passes parsed JSON around. Field names are converted to snake_case with the original key kept in a comment, and keys missing from some array elements become Optional with a None default.

Questions

Dataclass or TypedDict — which should I choose?

TypedDict when you keep working with the parsed dict and just want type checking. Dataclass when you want real objects with attribute access and a constructor, and are willing to write the conversion step.

Why do optional fields default to None?

Dataclasses require that any field with a default comes after fields without one. Defaulting optional fields to None keeps the generated class constructible without reordering your data.

Do the snake_case names still match my JSON keys?

Not automatically — dataclasses do not rename on deserialization. The original key is kept in a trailing comment so you can wire up a mapping, or use pydantic's alias support if you need it enforced.