diff --git a/sanic/request.py b/sanic/request.py index 27ff011e..aa778a8d 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -69,10 +69,10 @@ class Request(dict): self.stream = None @property - def json(self): + def json(self, loads=json_loads): if self.parsed_json is None: try: - self.parsed_json = json_loads(self.body) + self.parsed_json = loads(self.body) except Exception: if not self.body: return None diff --git a/sanic/response.py b/sanic/response.py index 3b0ef449..f661758b 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -237,7 +237,8 @@ class HTTPResponse(BaseHTTPResponse): def json(body, status=200, headers=None, - content_type="application/json", **kwargs): + content_type="application/json", dumps=json_dumps, + **kwargs): """ Returns response object with body in json format. @@ -246,7 +247,7 @@ def json(body, status=200, headers=None, :param headers: Custom Headers. :param kwargs: Remaining arguments that are passed to the json encoder. """ - return HTTPResponse(json_dumps(body, **kwargs), headers=headers, + return HTTPResponse(dumps(body, **kwargs), headers=headers, status=status, content_type=content_type)