import codecs
import json


def _load_list(file_name, object_type="licenses", id_attribute="licenseId"):
    """
    Return a list version tuple and a mapping of licenses
    name->id and id->name loaded from a JSON file
    from https://github.com/spdx/license-list-data
    """
    licenses_map = {}
    with codecs.open(file_name, "rb", encoding="utf-8") as lics:
        licenses = json.load(lics)
    version = tuple(licenses["licenseListVersion"].split("."))
    for lic in licenses[object_type]:
        if lic.get("isDeprecatedLicenseId"):
            continue
        name = lic["name"]
        identifier = lic[id_attribute]
        licenses_map[name] = identifier
        licenses_map[identifier] = name
    return version, licenses_map