JSON to Python API
Generate Python classes (dataclasses, Pydantic v2 models or TypedDicts) with type hints from a sample JSON document. Keys become snake_case fields, with aliases where needed.
POST /api/v1/tools/json-to-pythonMCP json_to_pythonDeveloper ToolsGenerate Python dataclasses, Pydantic v2 models or TypedDicts from JSON, with snake_case fields, aliases for renamed keys, Optional types and nested classes.
Input
Send these as a JSON object. Unknown fields are rejected.
- input
- A sample JSON document (object or array). (string, required)
- rootName
- Name of the top-level class; must be a valid Python identifier. (string, up to 100 characters, default "Root")
- style
- Output style. (string, one of dataclass, pydantic, typeddict, default "dataclass")
curl https://pithlab.com/api/v1/tools/json-to-python \n -H "Authorization: Bearer $PITHLAB_KEY" \n -H "Content-Type: application/json" \n -d '{"input":"{\"userId\":42,\"name\":\"Ada\",\"isActive\":true,\"tags\":[\"admin\"]}","rootName":"User","style":"pydantic"}'Example response
{
"ok": true,
"result": {
"output": "from pydantic import BaseModel, Field\n\n\nclass User(BaseModel):\n user_id: int = Field(alias=\"userId\")\n name: str\n is_active: bool = Field(alias=\"isActive\")\n tags: list[str]\n"
}
}