Return data in node-link format that is suitable for JSON serialization and use in Javascript documents.
Parameters: | G : NetworkX graph attrs : dict
|
---|---|
Returns: | data : dict
|
Raises: | NetworkXError :
|
See also
Notes
Graph, node, and link attributes are stored in this format but keys for attributes must be strings if you want to serialize with JSON.
The default value of attrs will be changed in a future release of NetworkX.
Examples
>>> from networkx.readwrite import json_graph
>>> G = nx.Graph([(1,2)])
>>> data = json_graph.node_link_data(G)
To serialize with json
>>> import json
>>> s = json.dumps(data)