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