JSON to Pydantic Model
Paste a sample JSON object below and generate Pydantic v2 `BaseModel` classes. The tool infers a Python type for every field and creates a named model for each nested object, so you get validated parsing with `Model.model_validate(data)`.
Runs entirely in your browser — your JSON is never uploaded. Emits Pydantic v2 models with nested models defined in the right order and Field aliases for non-identifier keys, so model_validate works immediately. No sign-up, no ads in the output.
How to generate a Pydantic model from JSON
- Paste your JSON. Paste one representative JSON object into the box above.
- Generate the model. Click Generate Pydantic model. The tool infers a type for every field and emits a BaseModel for the root and each nested object.
- Validate your data. Copy the classes into your project and call Root.model_validate(data) or model_validate_json(raw) to parse and validate.
How the type mapping works
Each JSON value maps to a Python type: a whole number becomes int, a decimal becomes float, a string becomes str, true/false becomes bool, and null becomes Any. Arrays become List[T] using the type of the first element. Keys that are not valid Python identifiers (e.g. full-name) get a Field(alias="...") so Pydantic can still populate them.
Nested objects
Every nested object becomes its own BaseModel, defined before the model that references it, so the module imports and runs as-is on Pydantic v2. Parse with Root.model_validate(data) or Root.model_validate_json(raw).
Using the result
Pydantic validates types at construction and raises a clear ValidationError when the data does not match — the reason it is the standard for request bodies in FastAPI and for structured LLM output.
FAQ
Is this Pydantic v1 or v2?
v2. Models subclass BaseModel and you parse with model_validate / model_validate_json. For v1 the equivalent calls are parse_obj / parse_raw.
How are keys like 'full-name' handled?
They are not valid Python identifiers, so the field is renamed to a safe name (full_name) and given Field(alias="full-name"). To populate by alias enable populate_by_name or validate from the raw dict.
How do I mark fields optional?
A single sample cannot tell which keys are sometimes missing. Wrap those types in Optional[T] and give them a default (e.g. = None) so validation passes when the key is absent.