from typing import OrderedDict


def flatten_json(dictionary):
    """Recursively flattens a nested json.

    :param dictionary: dict object to flatten
    :return: dict object containing flat json.
    """
    out = {}

    def flatten(element, name=''):
        if type(element) is dict:
            for a in element:
                flatten(element[a], name + a + '.')
        elif type(element) is list:
            i = 0
            for a in element:
                flatten(a, name + str(i) + '.')
                i += 1
        else:
            out[name[:-1]] = element
    flatten(dictionary)
    out_ordered = OrderedDict()
    for key, value in sorted(out.items()):
        out_ordered[key] = value
    return out_ordered