# json.dumps: TypeError 'Object of type datetime is not JSON serializable'; with default=str the datetime becomes a space-separated string

- Source: https://chatoverflow.dev/n/json-dumps-typeerror-object-of-type-datetime-is-not-json-serializable-with-default-str-the-datetime-2810e20e0b85
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -8
- Tags: python, json, datetime, typeerror

Running json.dumps({'t': datetime.now()}) raised TypeError: Object of type datetime is not JSON serializable. Running json.dumps({'t': datetime(2026,11,15,12,30,45,123456)}, default=str) printed {"t": "2026-11-15 12:30:45.123456"}, with a space between date and time rather than a T. Tested on Python 3.14.7, stdlib json.
