JSON to Pydantic
Paste or drop your data here, or open a file.
New to Bracely?
Everything stays in your browser.
Output appears here
Paste or open your data in the input box. It never leaves your browser.
JSON to Pydantic
Paste a JSON sample, such as an API response, and Bracely writes Pydantic v2 models for it. Each object becomes a BaseModel class with type hints. Keys that aren't snake_case keep their JSON name through Field(alias=...), with populate_by_name so either name works, and fields missing from some items become Optional with a None default.
Example: a FastAPI order body from a JavaScript front end
The front end sends camelCase keys and only some orders have a gift note. Each key gets a snake_case field with Field(alias=…), so Python code reads order.customer_email while the JSON keeps customerEmail, and giftNote becomes Optional with a None default:
Input
[
{
"orderId": "ORD-20419",
"customerEmail": "ananya@example.com",
"items": [
{
"sku": "KB-01",
"qty": 1,
"unitPrice": 2499
}
],
"giftNote": "Happy birthday",
"placedAt": "2026-10-29T10:00:00Z"
},
{
"orderId": "ORD-20420",
"customerEmail": "kabir@example.com",
"items": [
{
"sku": "MS-02",
"qty": 2,
"unitPrice": 799.5
}
],
"placedAt": "2026-10-29T11:30:00Z"
}
]Output
from __future__ import annotations
from typing import Optional
from pydantic import BaseModel, ConfigDict, Field
class Item(BaseModel):
model_config = ConfigDict(populate_by_name=True)
sku: str
qty: int
unit_price: float = Field(alias="unitPrice")
class Order(BaseModel):
model_config = ConfigDict(populate_by_name=True)
order_id: str = Field(alias="orderId")
customer_email: str = Field(alias="customerEmail")
items: list[Item]
gift_note: Optional[str] = Field(None, alias="giftNote")
placed_at: str = Field(alias="placedAt")
OrderList = list[Order]
How do I use the JSON to Pydantic?
- Paste a JSON sample.
- Set the root type name, for example Order.
- Copy the Pydantic code into your project.
What does the JSON to Pydantic do?
- BaseModel classes with int, float, str and bool hints
- Field(alias=...) for camelCase and other JSON names
- Optional[...] = None for fields that can be missing
- Nested objects become their own named types
- 20 other languages from the same sample, including TypeScript
When to use the JSON to Pydantic
FastAPI, LangChain and most modern Python services describe request and response bodies as Pydantic models, which validate data as it arrives and give your editor real types. Writing them by hand from a JSON payload is slow and easy to get wrong; paste a real body instead and copy models that already match it.
Keys that aren't Python style, like the camelCase a JavaScript front end sends, get snake_case field names with Field(alias=…), and model_config enables populate_by_name so code can use either name. Whole numbers become int, decimals float, and a value that's an int in one item and a decimal in another becomes float. Fields missing from some items are Optional with a None default. These are Pydantic v2 models: ConfigDict and model_config don't exist in v1.
Frequently asked questions
- How do I parse and send the JSON?
- Order.model_validate(data) checks the JSON and builds the model. To send camelCase back, use order.model_dump(by_alias=True), or model_dump_json(by_alias=True) for a string.
- Why are dates str and not datetime?
- JSON has no date type, so the sample only shows text. Change the hint to datetime and Pydantic parses ISO strings such as 2026-10-29T10:00:00Z for you.
- How does it pick Pydantic types?
- From the values in your sample: whole numbers, decimals, text, true/false, arrays and nested objects. When array items disagree, the field is made optional or widened.
- Can I generate other languages?
- Yes. Change Language to any of the others: TypeScript, Go, Python, Java, C#, Kotlin, Swift, Rust, Scala, Ruby, Dart, PHP, Zod, TypeBox, Valibot, Yup, GraphQL, Protobuf, Prisma and Drizzle.
- Is my data uploaded?
- No. Bracely runs entirely in your browser, so nothing you paste or open leaves your device.
More JSON tools
Bracely has 104 JSON tools in one page. Related ones:
- JSON to TypeBox
- JSON to Valibot
- JSON to Yup
- JSON to Prisma
- JSON to Drizzle
- JSON to Scala
- JSON to Ruby
- JSON Schema builder
- JSON Schema validator
- JSON data dictionary
- OpenAPI from JSON
- JSON to ER diagram
- JSON Schema to TypeScript
- OpenAPI to TypeScript
- JSON to .env
- Excel to JSON
- Edge-case test data
- Password generator
- HTML to JSX
- SVG to JSX
- JSON Formatter
- JSON Validator
- JSON Viewer
- JSON Repair
- JSON Diff
- JSON to YAML
- JSON to CSV
- jq Playground
Runs entirely in your browser. Nothing you paste is uploaded. Made by Saurabh Pagrut · About · Privacy policy
Last updated · Version 6.1 · Changelog
Saurabh Pagrut on GitHub · LinkedIn · X · YouTube · Instagram