def clean_for_serialization(self, data):
        """Clean data in preparation for serialization.

        Deletes items having key either a BSON, datetime, dict or a list instance, or
        starting with __.

        Args:
            data: Sample data to be serialized.

        Returns:
            Cleaned data dictionary.
        """

        if isinstance(data, dict):
            for k in data.keys():
                if (k.startswith('__')): 
                    del data[k]
                elif isinstance(data[k], bson.objectid.ObjectId): 
                    del data[k]
                elif isinstance(data[k], datetime.datetime):
                    data[k] = data[k].isoformat()+'Z'
                elif isinstance(data[k], dict):
                    data[k] = self.clean_for_serialization(data[k])
                elif isinstance(data[k], list):
                    data[k] = [self.clean_for_serialization(item) for item in data[k]]
        return data
Clean data in preparation for serialization.

        Deletes items having key either a BSON, datetime, dict or a list instance, or
        starting with __.

        Args:
            data: Sample data to be serialized.

        Returns:
            Cleaned data dictionary.