Is there way to get a JSON representation of a graph built with arbor.js?

918 Views Asked by At

I am building a graph using the arbor.js library.

I build my graph using the addNode() and addEdge() functions of arbor.js. And now I would like to retrieve the built graph using something like .toJson() that should be of the following form:

{nodes:{}, edges:{}}

where the nodes attribute contains a mapping of node names to data objects. For example,

{ nodes:{foo:{color:"red", mass:2},
         bar:{color:"green"}} }

and the edges attribute contains nested objects to map source identifier to target, then target to edge data object. e.g,

{ edges:{bar:{foo:{similarity:0},
              baz:{similarity:.666}} }
1

There are 1 best solutions below

0
On BEST ANSWER

I would start with the eachNode, eachEdge, getNodes and getEdges methods, use those to process the entire graph and create a json object using what those methods return. It does not look like there is a built in method to "traverse the graph and build a json object".