Usage:

$ dot -Tjson input.dot
$ dot -Tjson0 input.dot
$ dot -Tdot_json input.dot
$ dot -Txdot_json input.dot

JSON

JavaScript Object Notation

These formats produce a JSON output encoding the DOT language. Using json0 produces output in JSON format that contains the same information produced by -Tdot. Using json produces output in JSON format that contains the same information produced by -Txdot. Both of these assume the graph has been processed by one of the layout algorithms. The dot_json and xdot_json also produce JSON output similar to to json0 and json, respectively, except they only use the content of the graph on input. In particular, they do not assume that the graph has been processed by any layout algorithm, and the only xdot information appearing in the output was in the original input file.

The output produced by these follows the json schema shown below. Note that the objects array has all of the subgraphs first, followed by all of the nodes. The _gvid value is the index of the subgraph or node in the objects array. This also holds true for the edges in the objects array. Note that this format allows clustered graphs, where edges can connect clusters as well as nodes.

Example: simple graph rendered with -Tdot_json

$ echo 'digraph { a->b }' | dot -Tdot_json
{
  "name": "%3",
  "directed": true,
  "strict": false,
  "_subgraph_cnt": 0,
  "objects": [
    {
      "_gvid": 0,
      "name": "a",
      "label": "\\N"
    },
    {
      "_gvid": 1,
      "name": "b",
      "label": "\\N"
    }
  ],
  "edges": [
    {
      "_gvid": 0,
      "tail": 0,
      "head": 1
    }
  ]
}

Example: simple graph rendered with -Txdot_json

$ echo 'digraph { a->b }' | dot -Txdot_json
{
  "name": "%3",
  "directed": true,
  "strict": false,
  "_subgraph_cnt": 0,
  "objects": [
    {
      "_gvid": 0,
      "name": "a",
      "label": "\\N"
    },
    {
      "_gvid": 1,
      "name": "b",
      "label": "\\N"
    }
  ],
  "edges": [
    {
      "_gvid": 0,
      "tail": 0,
      "head": 1
    }
  ]
}

Example: simple graph rendered with -Tjson0

$ echo 'digraph { a->b }' | dot -Tjson0
{
  "name": "%3",
  "directed": true,
  "strict": false,
  "bb": "0,0,54,108",
  "_subgraph_cnt": 0,
  "objects": [
    {
      "_gvid": 0,
      "name": "a",
      "height": "0.5",
      "label": "\\N",
      "pos": "27,90",
      "width": "0.75"
    },
    {
      "_gvid": 1,
      "name": "b",
      "height": "0.5",
      "label": "\\N",
      "pos": "27,18",
      "width": "0.75"
    }
  ],
  "edges": [
    {
      "_gvid": 0,
      "tail": 0,
      "head": 1,
      "pos": "e,27,36.104 27,71.697 27,63.983 27,54.712 27,46.112"
    }
  ]
}

Example: simple graph rendered with -Tjson

echo 'digraph { a->b }' | dot -Tjson
{
  "name": "%3",
  "directed": true,
  "strict": false,
  "_draw_": 
  [
    {
      "op": "c",
      "grad": "none",
      "color": "#fffffe00"
    },
    {
      "op": "C",
      "grad": "none",
      "color": "#ffffff"
    },
    {
      "op": "P",
      "points": [[0.000,0.000],[0.000,108.000],[54.000,108.000],[54.000,0.000]]
    }
  ],
  "bb": "0,0,54,108",
  "xdotversion": "1.7",
  "_subgraph_cnt": 0,
  "objects": [
    {
      "_gvid": 0,
      "name": "a",
      "_draw_": 
      [
        {
          "op": "c",
          "grad": "none",
          "color": "#000000"
        },
        {
          "op": "e",
          "rect": [27.000,90.000,27.000,18.000]
        }
      ],
      "_ldraw_": 
      [
        {
          "op": "F",
          "size": 14.000,
          "face": "Times-Roman"
        },
        {
          "op": "c",
          "grad": "none",
          "color": "#000000"
        },
        {
          "op": "T",
          "pt": [27.000,86.300],
          "align": "c",
          "width": 7.000,
          "text": "a"
        }
      ],
      "height": "0.5",
      "label": "\\N",
      "pos": "27,90",
      "width": "0.75"
    },
    {
      "_gvid": 1,
      "name": "b",
      "_draw_": 
      [
        {
          "op": "c",
          "grad": "none",
          "color": "#000000"
        },
        {
          "op": "e",
          "rect": [27.000,18.000,27.000,18.000]
        }
      ],
      "_ldraw_": 
      [
        {
          "op": "F",
          "size": 14.000,
          "face": "Times-Roman"
        },
        {
          "op": "c",
          "grad": "none",
          "color": "#000000"
        },
        {
          "op": "T",
          "pt": [27.000,14.300],
          "align": "c",
          "width": 7.000,
          "text": "b"
        }
      ],
      "height": "0.5",
      "label": "\\N",
      "pos": "27,18",
      "width": "0.75"
    }
  ],
  "edges": [
    {
      "_gvid": 0,
      "tail": 0,
      "head": 1,
      "_draw_": 
      [
        {
          "op": "c",
          "grad": "none",
          "color": "#000000"
        },
        {
          "op": "b",
          "points": [[27.000,71.700],[27.000,63.980],[27.000,54.710],[27.000,46.110]]
        }
      ],
      "_hdraw_": 
      [
        {
          "op": "S",
          "style": "solid"
        },
        {
          "op": "c",
          "grad": "none",
          "color": "#000000"
        },
        {
          "op": "C",
          "grad": "none",
          "color": "#000000"
        },
        {
          "op": "P",
          "points": [[30.500,46.100],[27.000,36.100],[23.500,46.100]]
        }
      ],
      "pos": "e,27,36.104 27,71.697 27,63.983 27,54.712 27,46.112"
    }
  ]
}
descriptionJSON representation of a graph encoding xdot attributes
titleGraphviz JSON
required
  • name
  • directed
  • strict
  • _subgraph_cnt
definitions
drawops
items
oneOf
$ref
#/definitions/ellipse
#/definitions/polygon
#/definitions/polyline
#/definitions/bspline
#/definitions/text
#/definitions/font_style
#/definitions/drawcolor
#/definitions/font
#/definitions/style
typearray
style
required
  • op
  • style
typeobject
properties
style
typestring
op
patternS
typestring
font_style
required
  • op
  • fontchar
typeobject
properties
op
patternt
typestring
fontchar
minimum0
typeinteger
maximum127
polygon
required
  • op
  • points
typeobject
properties
points
$ref#/definitions/pointlist
op
pattern[pP]
typestring
metanode
required
  • _gvid
  • name
typeobject
properties
_draw_
$ref#/definitions/drawops
name
typestring
descriptionThe node or subgraph name
_ldraw_
$ref#/definitions/drawops
_gvid
typeinteger
subgraphs
items
typeinteger
typearray
descriptionindex of a child subgraph
edges
items
typeinteger
typearray
descriptionindex of an edge in this subgraph
additionalProperties
typestring
nodes
items
typeinteger
typearray
descriptionindex of a node in this subgraph
titlenode or subgraph
color
pattern(#[0-9a-f]*)|(#[0-9a-f]{8})
typestring
text
required
  • op
  • pt
  • align
  • text
  • width
typeobject
properties
text
typestring
align
pattern[lcr]
typestring
op
patternT
typestring
pt
$ref#/definitions/point
width
typenumber
point
minItems2
items
typenumber
typearray
maxItems2
stop
required
  • frac
  • color
typeobject
properties
color
$ref#/definitions/color
frac
typenumber
drawcolor
required
  • op
  • grad
typeobject
properties
p0
oneOf
$ref
#/definitions/point
#/definitions/point3
p1
oneOf
$ref
#/definitions/point
#/definitions/point3
color
$ref#/definitions/color
stops
items
$ref#/definitions/stop
typearray
grad
enum
  • none
  • linear
  • radial
typestring
op
pattern[cC]
typestring
ellipse
required
  • op
  • rect
typeobject
properties
rect
$ref#/definitions/rectangle
op
pattern[eE]
typestring
bspline
required
  • op
  • points
typeobject
properties
points
$ref#/definitions/pointlist
op
pattern[bB]
typestring
edge
required
  • _gvid
  • tail
  • head
typeobject
properties
_hldraw_
$ref#/definitions/drawops
_tdraw_
$ref#/definitions/drawops
_draw_
$ref#/definitions/drawops
_ldraw_
$ref#/definitions/drawops
_gvid
typeinteger
tail
typeinteger
description_gvid of tail node
_tldraw_
$ref#/definitions/drawops
_hdraw_
$ref#/definitions/drawops
additionalProperties
typestring
head
typeinteger
description_gvid of tail head
titleedge
polyline
required
  • op
  • points
typeobject
properties
points
$ref#/definitions/pointlist
op
patternL
typestring
font
required
  • op
  • size
  • face
typeobject
properties
size
minimum0
typenumber
op
patternF
typestring
face
typestring
point3
minItems3
items
typenumber
typearray
maxItems3
rectangle
minItems4
items
typenumber
typearray
maxItems4
pointlist
items
$ref#/definitions/point
typearray
typeobject
properties
directed
typeboolean
descriptionTrue if the graph is directed
_draw_
$ref#/definitions/drawops
name
typestring
descriptionThe graph name
objects
items
$ref#/definitions/metanode
typearray
descriptionThe graph's subgraphs followed by the graph's nodes
_ldraw_
$ref#/definitions/drawops
strict
typeboolean
descriptionTrue if the graph is strict
edges
items
$ref#/definitions/edge
typearray
additionalProperties
typestring
_subgraph_cnt
typeinteger
descriptionNumber of subgraphs in the graph

Last modified June 19, 2021 : Add examples for plaintext formats. (0dc3efd)