# JSON to Pydantic > Free JSON to Pydantic converter that runs in the browser: paste JSON or drop a .json or JSON Lines file and get Pydantic v2 models, with optional and nullable fields worked out from every value, camelCase and awkward keys turned into snake_case attributes with aliases, and a second view in the API pattern (Base, Create, Update, Response). Nothing is uploaded. An optional, metered AI step suggests clearer class names, Literal types, string formats, descriptions and which fields the server sets, and the page checks each suggestion against every value before applying it. URL: https://json-to-pydantic.skillsafe.ai/ API: https://json-to-pydantic.skillsafe.ai/api.html ## What the free converter does (in the browser, no sign-in) - Reads strict JSON; reads JSON Lines (one value per line) as a list; removes // and /* */ comments and trailing commas when strict reading fails, and says so; otherwise reports the line and column where the text stops being JSON and why. - Looks at every value at every path. Each object becomes a class named from its key in PascalCase (items -> Item, people -> Person). Objects with the same name and the same fields share one class; different fields under the same name get the parent's name as a prefix. Classes are written children first, so no forward references are needed. - In a list of objects, a field missing in some items gets `= None`; a field that is sometimes null becomes `T | None` and stays required; mixed kinds become a union; a list that is always empty becomes list[Any]; an empty object becomes dict[str, Any]; a field that is always null becomes None and is listed so it can be set by hand. A top-level list or scalar becomes a RootModel. - Field names: snake_case with Field(alias="originalKey") and ConfigDict(populate_by_name=True) (or keep the keys). Python keywords, BaseModel attributes (json, copy, schema, validate, model_dump), names the file uses as types (date, list, str), leading digits or underscores and dashes or spaces get a safe name and an alias; no attribute ever takes another key's spelling. - Types: str, int, float, bool, nested models, list[...], and UUID, datetime, date, EmailStr, HttpUrl when every value fits. Python 3.10+ syntax (int | None) or Optional[int] / List[str] for 3.8+. Optional extra="forbid". - API view (the multi-model pattern from the skill): NameBase (fields a client sends), NameCreate(NameBase), NameUpdate (every field optional, for PATCH), NameResponse(NameBase) adding the server-set fields (the record's id and its created/updated timestamps by default), and optionally NameInDB with doc_type. - Every generated file was checked by running it under real Pydantic 2.14 (Python 3.13) and 2.13 (Python 3.9) against the JSON it came from. - Download the .py file of either view, or copy it. ## Optional AI step (sign-in, metered) Task id `refine`. Sends the generated plain models, the resource path and a summary of each class and field (path, key, attribute name, current type, how many objects have it, nullable, distinct count, detected format, the page's server-set guess and, if the visitor allows, up to 5 example values). Never the JSON itself. The model returns JSON: `names` (class renames by path), `enums` (fixed sets of string values, written as Literal), `formats` (uuid, date-time, date, email, url), `docs` (one-sentence descriptions, written as docstrings and Field(description=...)), `server` (the resource fields the server sets) and `notes`. The page applies a name only if no class with different fields has it, a set of values only if every value in the JSON is in it, a format only if every value fits, server fields only if they are direct fields of the resource, and lists what it refused and why. ## Sources Adapted from the agent skill @sickn33/pydantic-models-py (MIT), https://skillsafe.ai/skill/@sickn33/pydantic-models-py, from github.com/sickn33/antigravity-awesome-skills.