W3cubDocs

/Graphviz

JSON

JavaScript Object Notation

These formats produce a JSON output encoding the DOT language.

  • json0 produces output in JSON format that contains the same information produced by -Tdot.
  • 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.

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"
    }
  ]
}
description JSON representation of a graph encoding xdot attributes
title Graphviz 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
type array
style
required
  • op
  • style
type object
properties
style
type string
op
pattern S
type string
font_style
required
  • op
  • fontchar
type object
properties
op
pattern t
type string
fontchar
minimum 0
type integer
maximum 127
polygon
required
  • op
  • points
type object
properties
points
$ref #/definitions/pointlist
op
pattern [pP]
type string
metanode
required
  • _gvid
  • name
type object
properties
_draw_
$ref #/definitions/drawops
name
type string
description The node or subgraph name
_ldraw_
$ref #/definitions/drawops
_gvid
type integer
subgraphs
items
type integer
type array
description index of a child subgraph
edges
items
type integer
type array
description index of an edge in this subgraph
additionalProperties
type string
nodes
items
type integer
type array
description index of a node in this subgraph
title node or subgraph
color
pattern (#[0-9a-f]*)|(#[0-9a-f]{8})
type string
text
required
  • op
  • pt
  • align
  • text
  • width
type object
properties
text
type string
align
pattern [lcr]
type string
op
pattern T
type string
pt
$ref #/definitions/point
width
type number
point
minItems 2
items
type number
type array
maxItems 2
stop
required
  • frac
  • color
type object
properties
color
$ref #/definitions/color
frac
type number
drawcolor
required
  • op
  • grad
type object
properties
p0
oneOf
$ref
#/definitions/point
#/definitions/point3
p1
oneOf
$ref
#/definitions/point
#/definitions/point3
color
$ref #/definitions/color
stops
items
$ref #/definitions/stop
type array
grad
enum
  • none
  • linear
  • radial
type string
op
pattern [cC]
type string
ellipse
required
  • op
  • rect
type object
properties
rect
$ref #/definitions/rectangle
op
pattern [eE]
type string
bspline
required
  • op
  • points
type object
properties
points
$ref #/definitions/pointlist
op
pattern [bB]
type string
edge
required
  • _gvid
  • tail
  • head
type object
properties
_hldraw_
$ref #/definitions/drawops
_tdraw_
$ref #/definitions/drawops
_draw_
$ref #/definitions/drawops
_ldraw_
$ref #/definitions/drawops
_gvid
type integer
tail
type integer
description _gvid of tail node
_tldraw_
$ref #/definitions/drawops
_hdraw_
$ref #/definitions/drawops
additionalProperties
type string
head
type integer
description _gvid of tail head
title edge
polyline
required
  • op
  • points
type object
properties
points
$ref #/definitions/pointlist
op
pattern L
type string
font
required
  • op
  • size
  • face
type object
properties
size
minimum 0
type number
op
pattern F
type string
face
type string
point3
minItems 3
items
type number
type array
maxItems 3
rectangle
minItems 4
items
type number
type array
maxItems 4
pointlist
items
$ref #/definitions/point
type array
type object
properties
directed
type boolean
description True if the graph is directed
_draw_
$ref #/definitions/drawops
name
type string
description The graph name
objects
items
$ref #/definitions/metanode
type array
description The graph's subgraphs followed by the graph's nodes
_ldraw_
$ref #/definitions/drawops
strict
type boolean
description True if the graph is strict
edges
items
$ref #/definitions/edge
type array
additionalProperties
type string
_subgraph_cnt
type integer
description Number of subgraphs in the graph

© 2025 The Graphviz Authors
Licensed under the Eclipse Public License 1.0.
https://www.graphviz.org/docs/outputs/json/