Exports a DFA to a JSON file.

    If *path* do not exists, it will be created.

    :param dict dfa: DFA to export;
    :param str name: name of the output file;
    :param str path: path where to save the JSON file (default:
                     working directory)

def dfa_to_json(dfa: dict, name: str, path: str = './'):
    """ Exports a DFA to a JSON file.

    If *path* do not exists, it will be created.

    :param dict dfa: DFA to export;
    :param str name: name of the output file;
    :param str path: path where to save the JSON file (default:
                     working directory)
    """
    out = {
        'alphabet': list(dfa['alphabet']),
        'states': list(dfa['states']),
        'initial_state': dfa['initial_state'],
        'accepting_states': list(dfa['accepting_states']),
        'transitions': list()
    }

    for t in dfa['transitions']:
        out['transitions'].append(
            [t[0], t[1], dfa['transitions'][t]])

    if not os.path.exists(path):
        os.makedirs(path)
    file = open(os.path.join(path, name + '.json'), 'w')
    json.dump(out, file, sort_keys=True, indent=4)
    file.close()