Serialisation and JSON Schema
Serialisation and JSON Schema
Validation is the trip into a model. Serialisation is the trip back out: turning a Ticket with a datetime and a nested Customer into something a browser, a queue, or a language model can read. Pydantic gives you exact control over that trip, and the same model can also describe itself as a JSON Schema, so the shape you validate against is the shape you publish to clients and to tools.
The distinction to keep in mind is between a Python dump and a JSON dump. A Python dump keeps datetime and Decimal objects as they are, which is what you want when passing data between functions. A JSON dump turns them into strings and numbers that survive json.dumps, which is what you want at the edge.
Continue reading
Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.