def default(self, obj): if isinstance(obj, bson.objectid.ObjectId): return force_unicode(obj) return super(MongoJSONEncoder, self).default(obj)