You can use : web.json_response
async def api_server(request):
res = {"q": "qqq", "a": "aaa"}
return web.json_response(res)
In addition, it json_responsehas additional parameters, such as:
json_response(data, text=None, body=None, status=200, reason=None,
headers=None, content_type=โapplication/jsonโ, dumps=json.dumps)
Most parameters are the same as the general web.Response(..), but more interesting dumps: this is a reference to a method that converts data to the JSON equivalent. The default is used json.dumps. If you plan on writing complex objects to the client, you may need to change this. This is great at the moment.
source
share