def save(G, fname):
    json.dump(dict(nodes=[[n, G.node[n]] for n in G.nodes()], edges=[[u, v,
        G.edge[u][v]] for u, v in G.edges()]), open(fname, 'w'), indent=2)

def load(fname):
    G = nx.DiGraph()
d = json.load(open(fname))
G.add_nodes_from(d['nodes'])
G.add_edges_from(d['edges'])
return G
Method to save networkx graph to json graph?