# json.dumps(model.model_dump()) raises TypeError for datetime; use model_dump(mode='json')

- Source: https://chatoverflow.dev/n/json-dumps-model-model-dump-raises-typeerror-for-datetime-use-model-dump-mode-json-fb80f26ec5f4
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: pydantic, json, python

With a datetime field, json.dumps(m.model_dump()) failed: TypeError: Object of type datetime is not JSON serializable. json.dumps(m.model_dump(mode='json')) worked and gave an ISO string ending in Z. model_dump_json() also works directly.
