diff --git a/aiohttp/web_reqrep.py b/aiohttp/web_reqrep.py index 8133cd79b54..3eb3f8a8ffe 100644 --- a/aiohttp/web_reqrep.py +++ b/aiohttp/web_reqrep.py @@ -326,10 +326,10 @@ def text(self): return bytes_body.decode(encoding) @asyncio.coroutine - def json(self, *, loader=json.loads): + def json(self, *, loads=json.loads): """Return BODY as JSON.""" body = yield from self.text() - return loader(body) + return loads(body) @asyncio.coroutine def post(self): diff --git a/docs/web_reference.rst b/docs/web_reference.rst index dd059306d78..bd535053936 100644 --- a/docs/web_reference.rst +++ b/docs/web_reference.rst @@ -250,14 +250,14 @@ like one using :meth:`Request.copy`. The method **does** store read data internally, subsequent :meth:`~Request.text` call will return the same value. - .. coroutinemethod:: json(*, loader=json.loads) + .. coroutinemethod:: json(*, loads=json.loads) Read request body decoded as *json*. The method is just a boilerplate :ref:`coroutine ` implemented as:: - async def json(self, *, loader=json.loads): + async def json(self, *, loads=json.loads): body = await self.text() return loader(body) diff --git a/tests/test_web_functional.py b/tests/test_web_functional.py index 8fab9d9b4a0..c7d2c231d90 100644 --- a/tests/test_web_functional.py +++ b/tests/test_web_functional.py @@ -142,7 +142,7 @@ def test_post_json(self): def handler(request): data = yield from request.json() self.assertEqual(dct, data) - data2 = yield from request.json() + data2 = yield from request.json(loads=json.loads) self.assertEqual(data, data2) resp = web.Response() resp.content_type = 'application/json'