Omnikit
DevFilesMoneyAll tools
Ctrl K
Dev toolsFile toolsMoney calculatorsAll tools
HomeDeveloper toolsJSON to Python Class Converter
EnglishالعربيةবাংলাDeutschEspañolFrançaisPolskiPortuguêsРусский

JSON to Python Class Converter

dev

Turn a JSON sample into Python dataclasses, Pydantic models or TypedDicts with type hints

Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.

Paste a JSON sample and get Python dataclasses, Pydantic v2 models or TypedDicts with type hints. Whole numbers become int and any decimal makes a field float; a value that is null or missing becomes str | None with None as its default, and 3 class styles share the same inference.

Next:
  • JSON to Zod Paste a JSON sample and get a Zod schema with its z.infer type, ready to copy
  • JSON Formatter & Validator Format, validate, minify and sort JSON with exact error positions

How to convert JSON to a Python class

1

Paste a JSON sample, such as an API response, into the left box.

2

The Python classes appear as you type: one class per object, with type hints such as int, float, list[str] and str | None.

3

Choose dataclass, Pydantic or TypedDict, and Python 3.9 typing if your project is older than 3.10.

4

Press Copy, or Download to save models.py.

About JSON to Python Class Converter

Python reads JSON into dictionaries, and a class with type hints is what lets an editor, a type checker or Pydantic catch a misspelt key or a wrong type. This converter writes those classes from a sample, so a long API response becomes typed Python in one paste.

How types are chosen.

JSON value Python type
"text" str
true / false bool
42 (whole numbers only) int
4.5 (any decimal seen) float
null, and also a type str | None, or Optional[str]
only null, or mixed kinds Any
[ ... ] list[...]
{ } empty dict[str, Any]
{ ... } a class of its own

Arrays of objects. All the objects of an array are merged into one class, so a key that appears in only some of them is still there, typed to allow None and given None as its default. Two objects with exactly the same keys and types share one class.

Three styles. A dataclass needs nothing installed; fields with a default are moved after the others, because Python raises a TypeError otherwise. Pydantic models use snake_case attributes with Field(alias=...) for keys spelt differently, such as userName or first-name. A TypedDict keeps the keys exactly and marks the occasional ones NotRequired.

Order and names. Classes are written children first, so every name is defined before it is used. A keyword such as class becomes class_, and a key that would hide a type, such as list, gets the same underscore.

Every style was checked by running the output under CPython with Pydantic 2 and validating the sample. Nothing you paste leaves the browser.

Frequently asked questions

How do I convert JSON to a Python class?

Paste a JSON sample into the converter and the Python classes appear beside it, one per object, with a type hint on every attribute. Choose dataclass for plain classes, Pydantic for validation, or TypedDict to keep working with ordinary dictionaries, then copy the module into your project.

Should I use a dataclass, a Pydantic model or a TypedDict?

A dataclass suits data you build yourself and needs no library. Pydantic suits data from outside, such as API responses, because it checks every value and converts nested objects for you. A TypedDict only adds type hints to the dictionary json.loads returns, so it costs nothing at runtime.

How are JSON keys like userName or first-name handled?

Pydantic attributes are written in snake_case, as PEP 8 asks, with Field(alias="userName") so validation still reads the original key. A TypedDict keeps every key exactly, switching to the functional syntax when a key is not a valid name. A dataclass keeps keys that are valid names and notes the rest.

Why is a field typed str | None or Optional[str]?

A key that was null in the sample, or missing from some objects of an array, can hold None, so its hint allows it. Missing keys also get None as the default, and in a dataclass those fields move to the end, because Python refuses a field without a default after one with a default.

Which Python version does the output need?

The default typing, such as list[str] and str | None, needs Python 3.10 or later. Switch on Python 3.9 typing to get Optional and List from the typing module instead. NotRequired for TypedDict comes from typing_extensions, and is in typing itself from Python 3.11.

Is my JSON uploaded?

No. The conversion runs in your browser with no request to any server, and the JSON is not stored, so API responses holding tokens or personal data stay on your device. Close the tab and nothing remains.

Sources

  • Python documentation, dataclassesField order rule: no field without a default after one with a default
  • Python documentation, typing.TypedDict and NotRequiredClass and functional syntax, keys that may be missing
  • PEP 8, naming conventionsCapWords class names, snake_case attributes, a trailing underscore after a keyword
  • Pydantic documentation, fields and aliasesField(alias=...) to read a JSON key into another attribute name

Last verified 16 October 2026.

Rates and rules change; check the source before you rely on a figure.

Still stuck? Ask about JSON to Python Class Converter and anybody who knows can answer. No account needed.

Common uses

  • JSON to Pydantic ModelPaste an API response and get Pydantic v2 BaseModel classes with field aliases

Same job, other tools: TSV to JSON – Convert tab-separated values, such as a paste from Excel, into JSON · JSON to YAML – Turn JSON into clean, readable YAML for configs · Query String Parser – Split a URL query string into a table of decoded parameters.

Related tools

All developer tools
Base64 Encode & DecodeText and files to Base64 and back, with URL-safe mode and image previewUnix Timestamp ConverterUnix timestamps to dates and dates to timestamps, in any time zoneJSON to TypeScriptGenerate TypeScript interfaces or types from a JSON sampleCSV to JSONConvert CSV to JSON and JSON to CSV, with a table previewYAML to JSONConvert YAML to JSON and JSON to YAML, with anchors resolvedURL Encoder / DecoderPercent-encode or decode text and URLs, and see every part of a linkColor ConverterHEX, RGB, HSL, HWB, OKLCH and CMYK in both directions, with a contrast checkNumber Base ConverterBinary, octal, decimal, hex and any base to 36, exact at any size, with two's complement
Was this tool helpful?
Omnikit

Small jobs, done in your browser. Free, fast and private. Files are never uploaded.

Files

  • Compress Image
  • Image to PDF
  • Merge PDF
  • Compress PDF
  • PDF to Word
  • Word to PDF

Dev

  • JSON Formatter & Validator
  • Base64 Encode & Decode
  • JWT Decoder, Verifier & Encoder
  • Password Generator
  • UUID Generator
  • Unix Timestamp Converter

Money

  • SIP Calculator
  • EMI Calculator
  • GST Calculator
  • FD Calculator
  • PPF Calculator
  • Lumpsum Calculator
EnglishالعربيةবাংলাDeutschEspañolFrançaisPolskiPortuguêsРусский
GuidesQuestionsAboutHow we checkLaw library (beta)PrivacyTermsDisclosureContactMore: Exam practice (UGC NET Paper 1)Runs in your browser. Nothing is uploaded. © 2026 Omnikit (theomnikit.com)