Serialize the payload into JSON
349384
def serialize(self, root, records):
        """"""
        logging.info("Serializing record")
        logging.debug("Root: {}".format(root))
        logging.debug("Records: {}".format(records))
        if records == {}:
            return '{}'
        if isinstance(records, dict):
            if list(records.keys())[0] == 'errors':
                logging.warning("Found errors. Moving on".format(records))
                root = None
            elif '_id' in records:
                records['id'] = records.pop('_id')
        else:
            records = list(records)

            # rename _id to id
            for r in records:
                if '_id' in r:
                    r['id'] = r.pop('_id')

        if root is not None:
            records = {root: records}
        return json.dumps(records, cls=JSONEncoder)
314079
def class_to_json(obj):
    

    obj_raw = serialize(obj)

    return json.dumps(obj_raw, indent=_JSON_INDENT, sort_keys=True)
1101782
def to_json(self):
        """"""
        return {
            'tpm': self.tpm,
            'cm': self.cm,
            'size': self.size,
            'node_labels': self.node_labels
        }
359605
def to_json(self):
        """"""
        return {
            'header': self.header.to_json(),
            'values': self._values,
            'datetimes': self.datetimes,
            'validated_a_period': self._validated_a_period
        }
152757
def serialize(self):
        '''
        
        '''
        return {
            'name' : self.name,
            'weight' : self.weight,
            'value' : self.value,
            'msgs' : self.msgs,
            'children' : [i.serialize() for i in self.children]
        }
1324488
def serialize(obj):
    """"""
    if isinstance(obj, datetime.datetime):
        serial = obj.isoformat(sep='T')
        return serial

    if isinstance(obj, uuid.UUID):
        serial = str(obj)
        return serial

    try:
        return obj.__dict__
    except AttributeError:
        return str(obj)
    except Exception as e:
        strval = 'unknown obj'
        exceptval = 'unknown err'
        try:
            strval = str(obj)
            exceptval = repr(e)
        except Exception:
            pass
        return 'json fail {} {}'.format(exceptval, strval)
255493
def dumps(self) -> str:
        
        return json.dumps(self.data, sort_keys=True, indent=4)
1212451
def serialize(self):
        """"""
        # Serialize fields to a dict
        data = {}
        for field_name in self:
            value = self._values.get(field_name)
            field = self.fields.get(field_name)
            if value is not None:
                if field.all:
                    value = [field.serialize(v) for v in value]
                else:
                    value = field.serialize(value)
            # Skip empty fields unless field.null
            if not field.null and ((field.all and value == []) or (not field.all and value in {None, ''})):
                continue
            data[field.name] = value
        return data
255151
def to_dict(self):
        
        rv = dict(self.payload or ())
        rv["message"] = self.message
        return rv
367532
def to_json(self):
        

        result = super(Snapshot, self).to_json()
        result.update({
            'snapshot': self.snapshot.to_json(),
        })
        return result
976101
def to_json(self):
        

        result = super(Webhook, self).to_json()
        result.update({
            'name': self.name,
            'url': self.url,
            'topics': self.topics,
            'httpBasicUsername': self.http_basic_username,
            'headers': self.headers
        })

        if self.filters:
            result.update({'filters': self.filters})

        if self.transformation:
            result.update({'transformation': self.transformation})

        return result
960311
def to_json(self, value):
        """"""
        if not self.is_valid(value):
            raise ex.SerializeException('Invalid value: {}'.format(value))
        return value
725990
def _convert(self, payload):
        
        if not isinstance(payload, six.string_types):
            payload = json.dumps(payload, cls=DefaultJSONEncoder, sort_keys=True)
        return str(payload)
340273
def _serialize_json(obj, fp):
    
    json.dump(obj, fp, indent=4, default=serialize)
924130
def json(self, **kwargs):
        '''
        
        '''
        body = self._decompress(self.encoding)
        return _json.loads(body, **kwargs)
1061734
def to_json(self):
        

        web_resp = collections.OrderedDict()

        web_resp['status_code'] = self.status_code
        web_resp['status_text'] = dict(HTTP_CODES).get(self.status_code)
        web_resp['data'] = self.data if self.data is not None else {}
        web_resp['errors'] = self.errors or []

        return web_resp
894105
def serialize(self, obj, method='json', beautify=False, raise_exception=False):
        """"""

        return self.helper.string.serialization.serialize(
            obj=obj, method=method, beautify=beautify, raise_exception=raise_exception)