def to_json_type(self):
        def _convert_to_json(struct, doc):
            """
            convert all datetime to a timestamp from epoch
            """
            if struct is not None:
                for key in struct:
                    if isinstance(struct[key], datetime.datetime):
                        struct[key] = totimestamp(struct[key])
                    elif isinstance(struct[key], ObjectId):
                        #struct[key] = str(struct[key])
                        struct[key] = {'$oid': str(struct[key])}
                    elif isinstance(struct[key], dict):
                        _convert_to_json(struct[key], doc)
                    elif isinstance(struct[key], list) and len(struct[key]):
                        if isinstance(struct[key][0], dict):
                            for obj in struct[key]:
                                _convert_to_json(obj, doc)
                        elif isinstance(struct[key][0], datetime.datetime):
                            struct[key] = [totimestamp(obj) for obj in struct[key]]
                        elif isinstance(struct[key][0], ObjectId):
                            #struct[key] = [str(obj) for obj in struct[key]]
                            struct[key] = [{'$oid': str(obj)} for obj in struct[key]]
        # we don't want to touch our document so we create another object
        self._process_custom_type('bson', self, self.structure)
        obj = deepcopy(self)
        self._process_custom_type('python', self, self.structure)
        _convert_to_json(obj, obj)
        if '_id' in obj:
            if isinstance(obj['_id'], ObjectId):
                obj['_id'] = {'$oid': str(obj['_id'])}
        return obj
convert all document field into json type
dataset/ETHPy150Open namlook/mongokit/mongokit/document.py/Document.to_json_type