JSON to Pydantic & Python Dataclasses
Generate Pydantic v2 models or standard Python dataclasses from JSON objects and arrays. No uploads, accounts, or external parser services.
Optional types apply to null or missing values. Field annotations apply to Pydantic models; required fields use Field(default=...). Renamed Pydantic fields retain their JSON keys as aliases.
Ready. Your JSON stays in this browser.
All conversion happens in this tab. No JSON is uploaded. Merger transfers use temporary tab storage and are removed as soon as they load.
Generate Pydantic v2 models from JSON
Paste a JSON response to infer str, int, float, bool, List, and nested Python classes. Child models appear before their parents. Object arrays are inferred across every item, not just the first. Mixed types use Union; null-only fields and empty arrays use Any because a sample cannot establish a stronger type.
Optional fields, aliases, and defaults
With Optional types enabled, fields that are null or absent in some array items accept None and default to None. Disabling it makes inferred fields required; null-only fields still use Any. Snake_case converts camelCase keys to Python naming conventions. Pydantic aliases preserve original keys; use model_dump(by_alias=True) when exporting them. Invalid identifiers and Python keywords are normalized automatically, with collision-safe names.
Standard Python dataclasses
Dataclasses use @dataclass(kw_only=True), requiring Python 3.10 or newer. They provide type hints but do not validate data or automatically construct nested classes from dictionaries. Renamed keys are recorded in field metadata as json_key for your own mapping code. Root arrays become a typed list alias in dataclass mode and a Pydantic v2 RootModel in Pydantic mode.
These are sample-inferred models, not a complete API schema. Review required fields, nullability, aliases, and numeric ranges before using generated code in production. Exact integers outside JavaScript’s safe range must be supplied as strings.
JSON Merger · JSON to TypeScript · JSON to Zod · JSON to Go Struct · JSON to TOML