import json


def get_groupsets(json_file):
    """Load groupset info from json file and return as a dictionary."""
    with open(json_file, 'r') as fin:
        datas = json.load(fin)

    groupsets = {}

    for line in datas['organisationUnitGroupSets']:
        if not line['organisationUnitGroups']:
            continue
        for group in line['organisationUnitGroups']:
            groupdict = {}
            groupdict['groupsetid'] = line['id']
            groupdict['groupsetname'] = line['name'].encode('utf-8')
            groupsets[group['id']] = groupdict

    return groupsets