json-schema-infer

Paste any JSON object, get a ready-to-use Pydantic model. Zero dependencies.

View on GitHub See Demo
install
$ pip install json-schema-infer

Input → Output

user.json
{ "id": 1, "name": "Alice", "score": 9.8, "active": true, "tags": ["admin"], "address": { "city": "Mumbai", "zip": "400001" } }
models.py
from typing import List from pydantic import BaseModel class AddressModel(BaseModel): city: str zip: str class UserModel(BaseModel): id: int name: str score: float active: bool tags: List[str] address: AddressModel

Type mapping

JSON typePython annotation
stringstr
integerint
floatfloat
booleanbool
nullOptional[Any]
arrayList[T]
objectNested BaseModel