def json(
        self,
        include_id=False,
        date_fmt=None,
        object_id_fmt=str,
    ):
        """ Helper method to convert to MongoDB documents to JSON

            This includes helpers to convert non-JSON compatible types
            to valid JSON types.  HOWEVER, it cannot recurse into nested
            classes.

        Args:
            include_id:    bool, True to cast _id to a str,
                           False to omit from the result
            date_fmt:      str-or-None:  None to cast to UNIX timestamp,
                           str (strftime format) to convert to string,
                           for example: '%Y-%m-%d_%H:%M:%S'
            object_id_fmt: type, Cast the bson.ObjectId's to this format,
                           or None to exclude.  This only applies to
                           ObjectId variables other than _id.
        Returns:
            dict
        """
        has_slots, d = _get_dict(self)
        _id = self._id
        if not include_id:
            self._id = None

        object_ids = {
            k: v for k, v in d.items()
            if isinstance(v, bson.ObjectId)
        }

        for k, v in object_ids.items():
            if object_id_fmt is None:
                setattr(self, k, None)
            else:
                setattr(self, k, object_id_fmt(v))

        datetimes = {
            k: v for k, v in d.items()
            if isinstance(v, datetime.datetime)
        }

        for k, v in datetimes.items():
            if date_fmt is None:
                ts = (
                    time.mktime(
                        v.timetuple(),
                    )
                    + v.microsecond
                    / 1e6
                )
                setattr(self, k, ts)
            else:
                setattr(self, k, v.strftime(date_fmt))

        j = marshal_dict(
            self,
            JSON_TYPES,
            'json',
            include_id=include_id,
            date_fmt=date_fmt,
            object_id_fmt=object_id_fmt,
        )
        self._id = _id

        for k, v in object_ids.items():
            setattr(self, k, v)

        for k, v in datetimes.items():
            setattr(self, k, v)

        return j
Helper method to convert to MongoDB documents to JSON

            This includes helpers to convert non-JSON compatible types
            to valid JSON types.  HOWEVER, it cannot recurse into nested
            classes.

        Args:
            include_id:    bool, True to cast _id to a str,
                           False to omit from the result
            date_fmt:      str-or-None:  None to cast to UNIX timestamp,
                           str (strftime format) to convert to string,
                           for example: '%Y-%m-%d_%H:%M:%S'
            object_id_fmt: type, Cast the bson.ObjectId's to this format,
                           or None to exclude.  This only applies to
                           ObjectId variables other than _id.
        Returns:
            dict