Paste an API response and get Pydantic v2 BaseModel classes with field aliases
Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.Validating an API response with Pydantic starts with a BaseModel for every object in it, and writing those by hand for a large response takes a while. Paste the response and get Pydantic v2 models: snake_case attributes, Field(alias=...) wherever the JSON key is spelled differently, int or float per field, and None as the default for keys some items leave out.
Paste or type your input.
Choose the options you need.
Press Ctrl+Enter, then copy or download.
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.
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.
Every style was checked by running the output under CPython with Pydantic 2 and validating the sample. Nothing you paste leaves the browser.
The rest of the article, and all 6 questions about JSON to Python Class Converter, are on the JSON to Python Class Converter page.
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.
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.
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.
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.
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.
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.