Returns response object with body in json format.

    :param body: Response data to be serialized.
    :param status: Response code.
    :param headers: Custom Headers.
    :param kwargs: Remaining arguments that are passed to the json encoder.
199004
def json(
    body,
    status=200,
    headers=None,
    content_type="application/json",
    dumps=json_dumps,
    **kwargs
):
    
    return HTTPResponse(
        dumps(body, **kwargs),
        headers=headers,
        status=status,
        content_type=content_type,
    )
1036369
def _as_json(self, response):
        
        # Assume ClientResponse has "body", and otherwise it's a requests.Response
        content = response.text() if hasattr(response, "body") else response.text
        try:
            return json.loads(content)
        except ValueError:
            raise DeserializationError(
                "Error occurred in deserializing the response body.")
710838
function Response(statusCode, headers, body) {
  this.statusCode = statusCode;
  this.headers = {};
  for (var key in headers) {
    this.headers[key.toLowerCase()] = headers[key];
  }
  this.body = body;
}
378323
def _from_json(cls, response_raw, wrapper=None):
        

        json = response_raw.body_bytes.decode()
        obj = converter.json_to_class(dict, json)
        value = converter.deserialize(
            cls,
            cls._unwrap_response_single(obj, wrapper)
        )

        return client.BunqResponse(value, response_raw.headers)
1038210
def body(self):
        
        if not self._responses:
            return None
        if self._responses[-1].code >= 400:
            return self._error_message()
        return self._deserialize()
835181
def _post(self, uri, data, headers=None):
        
        if not headers:
            headers = self._get_headers()

        logging.debug("URI=" + str(uri))
        logging.debug("HEADERS=" + str(headers))
        logging.debug("BODY=" + str(data))

        response = self.session.post(uri, headers=headers,
                data=json.dumps(data))

        logging.debug("STATUS=" + str(response.status_code))
        if response.status_code in [200, 201]:
            return response.json()
        else:
            logging.error(b"ERROR=" + response.content)
            response.raise_for_status()
1304581
def _get_pretty_body(headers, body):
    
    try:
        if CONTENT_TYPE_HEADER_NAME in headers:
            if XMLRenderer.DEFAULT_CONTENT_TYPE == headers[CONTENT_TYPE_HEADER_NAME]:
                xml_parsed = parseString(body)
                pretty_xml_as_string = xml_parsed.toprettyxml()
                return pretty_xml_as_string
            elif JSONRenderer.DEFAULT_CONTENT_TYPE == headers[CONTENT_TYPE_HEADER_NAME]:
                decoded_body = body.decode('utf-8')
                parsed = json.loads(decoded_body)
                return json.dumps(parsed, sort_keys=True, indent=4)
    except:
        pass
    finally:
        return body
475758
def jsonify(obj, status=200, headers=None):
    
    data = JSONEncoder().encode(obj)
    if 'callback' in request.args:
        cb = request.args.get('callback')
        data = '%s && %s(%s)' % (cb, cb, data)
    return Response(data, headers=headers, status=status,
                    mimetype='application/json')
541250
def json_to_response(self, action=None, json_status=None, success_url=None,
                         json_data=None, **response_kwargs):
        
        data = {
            "status": self.get_status(json_status),
            "action": self.get_action(action),
            "extra_data": self.get_json_data(json_data or {})
        }

        if self.action == AjaxResponseAction.REDIRECT:
            data["action_url"] = success_url or self.get_success_url()
        return JsonResponse(data, **response_kwargs)
539673
def _json_body_(cls):
        
        json = []
        for series_name, data in six.iteritems(cls._datapoints):
            json.append({'name': series_name,
                         'columns': cls._fields,
                         'points': [[getattr(point, k) for k in cls._fields]
                                    for point in data]
                         })
        return json
884840
def get_response(self, **kwargs):
        
        return Response(
            json.dumps({"error": self.message}),  # pylint: disable=exception-message-attribute
            status_code=self.status_code,
            content_type="application/json",
            charset="utf-8",
            **kwargs
        )
801494
def jsonify(self, status_code=None, message=None, headers=None):
        
        if status_code is None:
            status_code = self.status_code
        if message is None:
            message = self.message
        if headers is None:
            headers = self.headers
        response = flask.jsonify({
            'status_code': status_code,
            'error': repr(self),
            'message': message,
        })
        if status_code is not None:
            response.status_code = status_code
        if headers is not None:
            response.headers = headers
        return response
333789
def jsonify(self,
                data: Any,
                code: Union[int, Tuple[int, str, str]] = HTTPStatus.OK,
                headers: Optional[Dict[str, str]] = None,
                ):
        
        return jsonify(data), code, headers or {}
1303629
def body(cls, description=None, default=None, resource=DefaultResource, **options):
        
        return cls('body', In.Body, None, resource, description, required=True,
                   default=default, **options)
1152288
def normalize_body(self, b):
        
        if b is None: return ''

        if self.is_json():
            # TODO ???
            # I don't like this, if we have a content type but it isn't one
            # of the supported ones we were returning the exception, which threw
            # Jarid off, but now it just returns a string, which is not best either
            # my thought is we could have a body_type_subtype method that would 
            # make it possible to easily handle custom types
            # eg, "application/json" would become: self.body_application_json(b, is_error)
            b = json.dumps(b, cls=ResponseBody)

        else:
            # just return a string representation of body if no content type
            b = String(b, self.encoding)

        return b
980876
def make_response(status, headers, payload, environ):
    
    headers_dict = {}
    content_type = None
    for h in headers:
        if h[0].lower() == 'content-type':
            content_type = h[1]
        else:
            headers_dict[h[0]] = h[1]
    return HTTPResponse(body_bytes=payload, content_type=content_type,
                        status=int(status.split()[0]), headers=headers_dict)
995720
def _wrap_response(self, status=None, **kwargs):
        
        kwargs['status'] = status if status is not None else self._status.OK
        return kwargs