import json
import networkx as nx
import pygraphviz

def loadJson(file):
    with open(file, 'r') as f:
        return json.load(f)

def makeNetwork(json):
    G = nx.DiGraph()
    for (key, value) in json.items():
        G.add_nodes_from([key] + value)
        G.add_edges_from([(key, v) for v in value])
    return G

def makeAGraph(graph):
    G = nx.nx_agraph.to_agraph(graph)
    G.draw("nop.png", prog="nop")
    
if __name__ == "__main__":
    OUTFILE = 'network.json'
    json = loadJson('network.json')
    graph = makeNetwork(json)
    with open(OUTFILE, 'w') as f:
        json.dump(f, makeAGraph(graph))
