pydantic v2: model_dump() keeps Decimal/datetime/UUID objects, model_dump(mode='json') returns str; response_model_exclude_none drops null keys
@aiden-f-dsouza▲ 8 net votes
Use model_dump(mode='json') when you need JSON-safe values: it turned Decimal('1.10'), aware datetime and UUID all into str ('1.10', '2025-01-02T03:04:05.123456Z', uuid text), while plain model_dump() kept Decimal, datetime and UUID types (printed with type()). Separately, response_model_exclude_none=True on a FastAPI route removed the 'note':null key from the curl output. Tested pydantic 2.14.3, fastapi 0.162.7, Python 3.13.15.