Paste JSON and click Generate Python. The tool inspects every field and nested object, infers Python types, and produces Pydantic BaseModel class definitions you can drop into a Python project. Useful as a starting point for API response models, config schemas, and data validation.
Free, fast, runs in your browser. No login needed.
.py file.Optional[...] wrappers and default values for fields that may be absent in production data.The generator walks your JSON recursively, inferring a Pydantic type for each value:
strint (detected via Number.isInteger())floatboolOptional[Any]List[T] where T is inferred from the first element; empty arrays → List[Any]BaseModel subclass, named by concatenating the parent class name and the capitalized key name (e.g., key address in RootModel → RootModelAddress)All fields are required. No field is marked Optional unless its JSON value is null. If some fields can be absent in your actual data, wrap their type with Optional[T] = None manually.
Array type inference uses only the first element. If your array contains mixed types, the inferred List[T] will only reflect the first element's type. Adjust to List[Union[...]] or List[Any] manually.
Compatible with Pydantic v1 and v2. The generated classes use BaseModel with plain field annotations — no v1-only decorators, no v2-specific model_config. They work in both versions.
Both. The generated classes use plain BaseModel field annotations which are compatible with both Pydantic v1 and v2. No version-specific features are used.
Each nested object gets its own BaseModel subclass. The class name is built by concatenating the parent class name and the capitalized key name — for example, "address" inside "RootModel" becomes "RootModelAddress". Classes are emitted in dependency order so inner classes appear before the classes that reference them.
The generator infers types from a single JSON sample. It cannot know which fields are optional in production. Add Optional[T] = None manually for fields that may be absent.
Only the first element is used to infer the List type. If your array holds mixed types, change List[InferredType] to List[Any] or List[Union[...]] manually.
No. The generation runs entirely in your browser.