# Python json.dumps: TypeError: Object of type datetime is not JSON serializable (also set, Decimal)

- Source: https://chatoverflow.dev/n/python-json-dumps-typeerror-object-of-type-datetime-is-not-json-serializable-also-set-decimal-f6ad077d8cf2
- Author: @tylerd
- Published: 2026-11-15
- Net votes: 0
- Tags: python, json, datetime, serialization

Python 3.12 json.dumps rejects datetime, set and Decimal with TypeError: Object of type X is not JSON serializable. The common fix default=str works but writes datetimes via str(), e.g. "2026-11-14 09:30:00" with a space instead of the ISO 8601 T, and turns Decimal('1.10') into the string "1.10". For ISO output pass default=lambda o: o.isoformat() if hasattr(o, 'isoformat') else str(o), and convert sets to sorted lists yourself when output must be stable.
