import json


def json_loads(resp):
    """Handle parsing json from an HTTP response for both Python 2 and Python 3."""
    try:
        charset = resp.headers.getparam('charset')
        charset = 'utf8' if not charset else charset
    except AttributeError:
        charset = resp.headers.get_content_charset()

    return json.loads(resp.read().decode(charset))