How to transform a dot graph to json graph?

dot, graphviz

Solution

`dot -Txdot_json -ogrpaph.json graph.dot `

See https://www.graphviz.org/doc/info/output.html#a:xdot_json

Problem

I want to use sigma.js to show some DOT graph. But it seems that sigma.js only support json graph format. Is there some bash tools or javascript module can transform a DOT graph to json graph? For example from DOT graph: ``` graph { n1 [Label = "n1"]; n2 [Label = "n2"]; n3 [Label = "n3"]; n1 -- n2; n1 -- n3; n2 -- n2; } ``` Transfer to JSON graph: ``` { "nodes": [ { "id": "n0", "label": "A node", "x": 0, "y": 0, "size": 3 }, { "id": "n1", "label": "Another node", "x": 3, "y": 1, "size": 2 }, { "id": "n2", "label": "And a last one", "x": 1, "y": 3, "size": 1 } ], "edges": [ { "id": "e0", "source": "n0", "target": "n1" }, { "id": "e1", "source": "n1", "target": "n2" }, { "id": "e2", "source": "n2", "target": "n0" } ] } ```

Original source