import json


def load_annotation_data(via_data_filename: str, only_img_annotations: bool=False, via_version: int=2) -> dict:
    """
    Load the content of via annotation files.

    :param via_data_filename: via annotations json file
    :param only_img_annotations: load only the images annotations ('_via_img_metadata' field)
    :param via_version:
    :return: the content of json file containing the region annotated
    """

    with open(via_data_filename, 'r', encoding='utf8') as f:
        content = json.load(f)
    if via_version == 2:
        assert '_via_img_metadata' in content.keys(), "The file is not a valid VIA project export."

        if only_img_annotations:
            return content['_via_img_metadata']
        else:
            return content
    else:
        return content