Skip to content

Instantly share code, notes, and snippets.

@mumrah
Created July 27, 2010 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mumrah/493062 to your computer and use it in GitHub Desktop.
Save mumrah/493062 to your computer and use it in GitHub Desktop.
from json import JSONEncoder
from pymongo.objectid import ObjectId
class MongoEncoder(JSONEncoder):
def _iterencode(self, o, markers=None):
if isinstance(o, ObjectId):
return """ObjectId("%s")""" % str(o)
else:
return JSONEncoder._iterencode(self, o, markers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment