Convert test client data to JSON
Flask 1.0 adds the get_json
method to the response object, similar to the request object. It handles parsing the response data as JSON, or raises an error if it can't.
data = response.get_json()
Prior to that, and prior to Python 3.6, json.loads
expects text, but data
is bytes. The response object provides the method get_data
, with the as_text
parameter to control this.
data = json.loads(response.get_data(as_text=True))