SchemaCraftby

JSON to Pydantic model converter

Paste JSON, JSON5, a Python dict or NDJSON and get BaseModel classes for FastAPI, instructor or the OpenAI SDK. The model is inferred from your samples, drawn as a pinout so you can check it, and written out ready to copy. Nothing leaves your browser.

Open the workbench with PYDANTIC-V2

What you get

  • One BaseModel per object, nested models declared first.
  • EmailStr, HttpUrl, datetime and Literal types from what was detected.
  • model_config = ConfigDict(extra="forbid") when strict is on, or Pydantic v1 Config.
  • X | None or Optional[X], your choice.

Example: a flight booking payload

The sample below has nested passengers, an itinerary and a payment. This is the Pydantic model SchemaCraft writes for it, with strict mode on.

booking.json · input

{
"booking_id": "bk_9f4c3a12-8e1b-4f72-9852-c62d08a5f331",
"pnr": "NOR742",
"status": "CONFIRMED",
"created_at": "2026-08-21T15:30:00Z",
"passengers": [
{
"passenger_id": "pax_01",
"first_name": "Sarah",
"last_name": "Connor",
"email": "sarah.connor@skyline.org",
"loyalty_tier": "PLATINUM",
"checked_bags": 2,
"special_meal": "VEGAN"
},
{
"passenger_id": "pax_02",
"first_name": "John",
"last_name": "Connor",
"email": "john.connor@skyline.org",
"loyalty_tier": "GOLD",
"checked_bags": 1,
"special_meal": null
}
],
"itinerary": {
"flight_number": "NA-204",
"origin": "SFO",
"destination": "HND",
"departure_time": "2026-09-15T11:45:00Z",
"arrival_time": "2026-09-16T15:30:00Z",
"duration_minutes": 645,
"cabin_class": "BUSINESS"
},
"payment": {
"amount": 3420.5,
"currency": "USD",
"is_settled": true,
"receipt_url": "https://pay.norai.dev/receipts/rec_891274"
}
}

FlightBookingRequest.py · PYDANTIC-V2

from datetime import datetime
from pydantic import BaseModel, Field
from pydantic import ConfigDict
from pydantic import EmailStr
from pydantic import HttpUrl
from typing import Any, Literal
class FlightBookingRequestPassengersItem(BaseModel):
model_config = ConfigDict(extra="forbid")
passenger_id: str = Field(..., description="Inferred passenger_id field")
first_name: str = Field(..., description="Inferred first_name field")
last_name: str = Field(..., description="Inferred last_name field")
email: EmailStr = Field(..., description="Inferred email field")
loyalty_tier: Literal["PLATINUM", "GOLD"] = Field(..., description="Inferred loyalty_tier field")
checked_bags: int = Field(..., description="Inferred checked_bags field")
special_meal: str | None = Field(default=None, description="Inferred special_meal field")
class FlightBookingRequestItinerary(BaseModel):
model_config = ConfigDict(extra="forbid")
flight_number: str = Field(..., description="Inferred flight_number field")
origin: str = Field(..., description="Inferred origin field")
destination: str = Field(..., description="Inferred destination field")
departure_time: datetime = Field(..., description="Inferred departure_time field")
arrival_time: datetime = Field(..., description="Inferred arrival_time field")
duration_minutes: int = Field(..., description="Inferred duration_minutes field")
cabin_class: str = Field(..., description="Inferred cabin_class field")
class FlightBookingRequestPayment(BaseModel):
model_config = ConfigDict(extra="forbid")
amount: float = Field(..., description="Inferred amount field")
currency: str = Field(..., description="Inferred currency field")
is_settled: bool = Field(..., description="Inferred is_settled field")
receipt_url: HttpUrl = Field(..., description="Inferred receipt_url field")
class FlightBookingRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
booking_id: str = Field(..., description="Inferred booking_id field")
pnr: str = Field(..., description="Inferred pnr field")
status: str = Field(..., description="Inferred status field")
created_at: datetime = Field(..., description="Inferred created_at field")
passengers: list[FlightBookingRequestPassengersItem] = Field(..., description="Inferred passengers field")
itinerary: FlightBookingRequestItinerary = Field(..., description="Inferred itinerary field")
payment: FlightBookingRequestPayment = Field(..., description="Inferred payment field")

Made by Nor AI

SchemaCraft is a free tool from Nor AI Technologies, an engineering studio in Ghazipur, Uttar Pradesh. We build custom AI, web and 3D software that runs in your own infrastructure, and you keep the code.

Wiring structured output or tool calling into your product, or need a typed data layer around an LLM pipeline? You talk to the engineers who write the code.