NetworkX

Previous topic

node_link_graph

Next topic

adjacency_graph

adjacency_data

adjacency_data(G)

Return data in adjacency format that is suitable for JSON serialization and use in Javascript documents.

Parameters :

G : NetworkX graph

Returns :

data : dict

A dictionary with node-link formatted data.

Notes

Graph, node, and link attributes will be written when using this format but attribute keys must be strings if you want to serialize the resulting data with JSON.

Examples

>>> from networkx.readwrite import json_graph
>>> G = nx.Graph([(1,2)])
>>> data = json_graph.adjacency_data(G)

To serialize with json

>>> import json
>>> s = json.dumps(data)