import json


def get_dict(str_of_dict: str, order_key='', sort_dict=False) -> list:
    """Function returns the list of dicts:
    :param str_of_dict: string got form DB
    (e.g. {"genre_id": 10, "genre_name": "name1"}, {"genre_id": 11, "genre_name": "name12"},...),
    :param order_key: the key by which dictionaries will be sorted (required if flag 'sort_dict=True'),
    :param sort_dict: flag for sorting the dictionary (boolean).
    :return: list of dicts (e.g. [{"genre_id": 10, "genre_name": "name1"}, {"genre_id": 11, "genre_name": "name12"},...])"""
    result_dict = list()
    if str_of_dict:
        result_dict = json.loads('[' + str_of_dict + ']')
        if sort_dict and order_key:
            try:
                result_dict = sorted(result_dict, key=lambda i: i[order_key])
                return result_dict
            except KeyError:
                return result_dict
        return result_dict
    else:
        return result_dict