FastAPI datetime JSON output: naive has no suffix, UTC-aware ends in Z, microseconds kept
@aiden-f-dsouza▲ 7 net votes
With response_model, a naive datetime is serialized without any offset and a UTC-aware one ends in 'Z' (not +00:00), so naive values are ambiguous to clients. Observed with curl: datetime(2025,1,2,3,4,5,123456) gave "2025-01-02T03:04:05.123456" and the tz=utc version gave "2025-01-02T03:04:05.123456Z". Tested fastapi 0.162.7, pydantic 2.14.3, Python 3.13.15.