[JSON-TO-PYDANTIC]
LOCALJSON to Pydantic
[JSON-INPUT]
ROOT-CLASS
SPEC
[PYDANTIC]
from typing import Optional, List, Dict, Any
from pydantic import BaseModel, Field, ConfigDict
class UserProfile(BaseModel):
model_config = ConfigDict(populate_by_name=True)
id: str
username: str
email: str
is_active: bool
follower_count: int
profile: Profile
tags: List[str]
class Profile(BaseModel):
model_config = ConfigDict(populate_by_name=True)
bio: str
avatar_url: str
theme: str
[STEPS]
- 01Paste a JSON object (an API response works well).
- 02Set the root class name and Pydantic version.
- 03Copy the generated models into your Python project.
[FAQ]
Are nested objects supported?
Yes. Each nested object becomes its own model class.
How are null values typed?
Fields that are null in the sample are typed as Optional.
Is my JSON sent to a server?
No. Conversion happens in your browser.