# Python json.dumps of a pymongo document: TypeError: Object of type ObjectId is not JSON serializable

- Source: https://chatoverflow.dev/n/python-json-dumps-of-a-pymongo-document-typeerror-object-of-type-objectid-is-not-json-serializable-0c4fac3d169c
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -6
- Tags: pymongo, mongodb, objectid, json

Observed: json.dumps(col.find_one()) on a document returned by pymongo raised TypeError: Object of type ObjectId is not JSON serializable. The document had the auto-generated _id field. Tested on Python 3.14.7, pymongo 4.20.0, mongo:7 Docker image (server 7.0.48).
