estyxx / typeddict-to-json

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Convert TypedDict into a JSON Schema

Usage

class Child(TypedDict):
    name: str

class Person(TypedDict):
    name: str
    age: Optional[int]
    children: list[Child]


assert schema == {
    "type": "object",
    "properties": {
        "name": {"type": "string"},
        "age": {"type": "integer"},
        "children": {
            "items": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"}
                },
                "required": ["name"],
            }
        },
    },
    "required": [
        "name",
        "accessories"
    ],
}

About


Languages

Language:Python 100.0%