Serialize resource(s) according to json-api spec.
430404
def serialize(self, resources):
        """"""
        serialized = {
            'meta': {
                'sqlalchemy_jsonapi_version': '4.0.9'
            },
            'jsonapi': {
                'version': '1.0'
            }
        }
        # Determine multiple resources by checking for SQLAlchemy query count.
        if hasattr(resources, 'count'):
            serialized['data'] = []
            for resource in resources:
                serialized['data'].append(
                    self._render_resource(resource))
        else:
            serialized['data'] = self._render_resource(resources)

        return serialized
722212
def encode_json(self, serializable):
        
        return json.dumps(serializable.serialize(), cls=self.encoder)
709057
def serialize_for_header(key, value):
    """"""
    if key in QUOTE_FIELDS:
        return json.dumps(value)
    elif isinstance(value, str):
        if " " in value or "\t" in value:
            return json.dumps(value)
        else:
            return value
    elif isinstance(value, list):
        return "[{}]".format(", ".join(value))
    else:
        return str(value)
142598
def dict_jsonify(param):
    """"""
    if not isinstance(param, dict):
        param = dict(param)
    return jsonify(param)
988600
def loadJson(self, data):
        """"""
        if not isinstance(data, dict):
            data = json.loads(data)
        self.__dict__.update(data)
        self.inflate() # restore objects from str values
        #if self.ports:  self._gotPorts = True
        return self
1300718
def json(self, **kwargs):
        """"""
        encoding = detect_encoding(self.content[:4])
        value = self.content.decode(encoding)

        return simplejson.loads(value, **kwargs)
1286664
def _build_resource(self):
        """"""
        resource = {"name": self.name}

        if self.dns_name is not None:
            resource["dnsName"] = self.dns_name

        if self.description is not None:
            resource["description"] = self.description

        if self.name_server_set is not None:
            resource["nameServerSet"] = self.name_server_set

        return resource
409033
def export_json(data, status, headers):
    
    dumped = json.dumps(data, ensure_ascii=False)
    resp = current_app.response_class(
        dumped, status=status, headers=headers,
        content_type='application/json; charset=utf-8')
    return resp
1293513
def _jsonify(x):
    """"""
    if isinstance(x, dict_class):
        return json.dumps(x._d, separators=(',', ':'))
    return json.dumps(x, separators=(',', ':'))
765921
def spl_json(self):
        """"""
        _splj = {}
        _splj["type"] = self._type
        _splj["value"] = self._value
        return _splj
8733
def dump_json(obj):
    """"""
    return simplejson.dumps(obj, ignore_nan=True, default=json_util.default)
434460
def to_json(self):
        
        endpoints = []
        for endpoint in self.endpoints:
            list_fields = endpoint.fields
            resource_type = endpoint.Meta.resource_type
            table = endpoint.Meta.table

            data = endpoint.to_dict()
            data['fields'] = resource_type.get_type_of_fields(
                list_fields,
                table,
            )
            endpoints.append(data)

        data = {
            'title': self.title,
            'endpoints': sorted(endpoints, key=lambda x: x['name']),
        }

        return json.dumps(data)
431923
def to_json(value, **kwargs):
        """"""
        if isinstance(value, HasProperties):
            return value.serialize(**kwargs)
        try:
            return json.loads(json.dumps(value))
        except TypeError:
            raise TypeError(
                "Cannot convert type {} to JSON without calling 'serialize' "
                "on an instance of Instance Property and registering a custom "
                "serializer".format(value.__class__.__name__)
            )
1147706
def _encode_request(self, request):
        """"""
        obj = request_to_dict(request, self.spider)
        return self.serializer.dumps(obj)
373528
def json_serial(cls, obj):
        """"""

        if isinstance(obj, datetime):
            serial = obj.isoformat()

        elif issubclass(obj.__class__, enum.Enum):
            serial = obj.value

        elif isinstance(obj, timedelta):
            serial = str(obj)

        elif isinstance(obj, set):
            serial = list(x for x in obj)

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

        # FIXME: if you want to add one more custom serializer, think twice about `singledispatch`

        else:
            raise TypeError("Type not serializable %s in %s" % (type(obj), obj))

        return serial
820866
def parse_resources(self, resources):
        """"""

        self.resources = {}
        resource_factory = ResourceFactory()
        for res_id, res_value in resources.items():
            r = resource_factory.create_resource(res_id, res_value)
            if r:
                if r.resource_type in self.resources:
                    self.resources[r.resource_type].append(r)
                else:
                    self.resources[r.resource_type] = [r]
964705
def _openapi_json(self):
        """"""
        # We don't use Flask.jsonify here as it would sort the keys
        # alphabetically while we want to preserve the order.
        from pprint import pprint
        pprint(self.to_dict())
        return current_app.response_class(json.dumps(self.to_dict(), indent=4),
                                          mimetype='application/json')