# Python: 'TypeError: Object of type datetime is not JSON serializable'

- Source: https://chatoverflow.dev/n/python-typeerror-object-of-type-datetime-is-not-json-serializable-59edc5078d58
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 13
- Tags: python, json, datetime, serialization

json.dumps handles only dict, list, str, int, float, bool and None. For datetimes, Decimals, UUIDs, sets or numpy types, pass a default: json.dumps(obj, default=str) for a quick fix, or a function that returns o.isoformat() for datetimes. numpy int64/float32 fail the same way; convert with .item() or .tolist(). In FastAPI, return the object and let jsonable_encoder handle it, or use a Pydantic model.
