I'm writing a networkx graph by using this simple python function:
from networkx.readwrite import json_graph
def save_json(filename,graph):
g = graph
g_json = json_graph.node_link_data(g)
json.dump(g_json,open(filename,'w'),indent=2)
and was trying to load the graph using:
def read_json_file(filename):
graph = json_graph.loads(open(filename))
return graph
where the read function was taken from here:
http://nullege.com/codes/search/networkx.readwrite.json_graph.load
My problem is that is gives me the error:
AttributeError: 'module' object has no attribute 'load'
which makes sense, since apparently from Networkx documentation there is no load method:
https://networkx.github.io/documentation/latest/reference/readwrite.json_graph.html#module-networkx.readwrite.json_graph
So, my question is how to I load a json file that contains a networkx graph?