import json


def get_json(response, code=None):
    """Extract json from response."""
    data = response.get_data(as_text=True)
    if code is not None:
        assert response.status_code == code, data
    return json.loads(data)