import json


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

    groups = {}

    for line in datas['organisationUnitGroups']:
        if not line['organisationUnits']:
            continue
        for unit in line['organisationUnits']:
            unitdict = {}
            unitdict['groupid'] = line['id']
            unitdict['groupname'] = line['name'].encode('utf-8')
            groups[unit['id']] = unitdict

    return groups