Loading...
Loading...
Paste JSON and get type-safe Pydantic v2 BaseModel classes. Handles nested objects, arrays, Optional fields, Field aliases, and generates FastAPI endpoint code.
from __future__ import annotations from pydantic import BaseModel, Field, ConfigDict class Assignee(BaseModel): model_config = ConfigDict(populate_by_name=True) user_id: int = Field(alias="userId") display_name: str = Field(alias="displayName") email_address: str = Field(alias="emailAddress") class Model(BaseModel): title: str description: str priority: int completed: bool due_date: str assignee: Assignee labels: list[str]
Pydantic is a Python data validation library that uses type annotations to validate and parse data at runtime. It automatically coerces types, raises clear validation errors, and generates JSON Schema from your models. It is the standard for data validation in FastAPI and is widely used across the Python ecosystem for API development, configuration management, and data processing.
The converter analyzes your JSON structure and infers Python types for each field. Strings become str, numbers become int or float, booleans become bool, arrays become list[T], and nested objects become their own Pydantic BaseModel classes. It also detects optional fields, generates Field aliases for non-Pythonic keys, and handles deeply nested structures recursively.
Pydantic maps JSON types to Python types: strings to str, integers to int, decimals to float, booleans to bool, null to None, arrays to list[T] with typed elements, and nested objects to separate BaseModel subclasses. It also supports Optional[T] (or T | None in v2) for fields that can be null, and dict[str, Any] for unstructured objects.
Yes. Pydantic handles nested JSON by generating a separate BaseModel class for each nested object. The parent model references the child model as a field type, so validation flows through the entire structure recursively. Arrays of objects are typed as list[ChildModel], and the converter automatically names nested models based on the parent field name.
Pydantic v2 is a major rewrite with a Rust-powered core (pydantic-core) that is 5 to 50 times faster than v1. Key API changes include model_validate() replacing parse_obj(), model_dump() replacing dict(), ConfigDict replacing inner Config classes, and field_validator replacing the validator decorator. This tool supports both v1 and v2 output syntax.