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

JSON

JavaScript 物件表示法

這些格式會產生一個 JSON 輸出,編碼 DOT 語言。

  • json0 會產生 JSON 格式的輸出,其中包含與 -Tdot 產生的相同資訊。
  • json 會產生 JSON 格式的輸出,其中包含與 -Txdot 產生的相同資訊。

這兩者都假設圖形已由其中一種版面配置演算法處理。

dot_jsonxdot_json 也會產生類似於 json0json 的 JSON 輸出,不同之處在於它們僅使用輸入的圖形內容。特別是,它們不假設圖形已由任何版面配置演算法處理,並且輸出中出現的唯一 xdot 資訊是在原始輸入檔案中。

這些產生的輸出遵循如下所示的 json 綱要。請注意,objects 陣列首先具有所有子圖,然後是所有節點。 _gvid 值是 objects 陣列中子圖或節點的索引。這也適用於 objects 陣列中的邊緣。請注意,此格式允許叢集圖形,其中邊緣可以連接叢集以及節點。

範例:使用 -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
    }
  ]
}
範例:使用 -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
    }
  ]
}
範例:使用 -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"
    }
  ]
}
範例:使用 -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"
    }
  ]
}
描述編碼 xdot 屬性的圖形 JSON 表示
標題Graphviz JSON
必要
  • 名稱
  • 定向
  • 嚴格
  • _subgraph_cnt
定義
繪圖操作
項目
oneOf
$ref
#/definitions/ellipse
#/definitions/polygon
#/definitions/polyline
#/definitions/bspline
#/definitions/text
#/definitions/font_style
#/definitions/drawcolor
#/definitions/font
#/definitions/style
類型陣列
style
必要
  • op
  • style
類型物件
屬性
style
類型string
op
模式S
類型string
font_style
必要
  • op
  • fontchar
類型物件
屬性
op
模式t
類型string
fontchar
最小值0
類型整數
最大值127
多邊形
必要
  • op
類型物件
屬性
$ref#/definitions/pointlist
op
模式[pP]
類型string
元節點
必要
  • _gvid
  • 名稱
類型物件
屬性
_draw_
$ref#/definitions/drawops
名稱
類型string
描述節點或子圖的名稱
_ldraw_
$ref#/definitions/drawops
_gvid
類型整數
子圖
項目
類型整數
類型陣列
描述子子圖的索引
邊緣
項目
類型整數
類型陣列
描述此子圖中邊緣的索引
additionalProperties
類型string
節點
項目
類型整數
類型陣列
描述此子圖中節點的索引
標題節點或子圖
color
模式(#[0-9a-f]*)|(#[0-9a-f]{8})
類型string
文字
必要
  • op
  • pt
  • 對齊
  • 文字
  • width
類型物件
屬性
文字
類型string
對齊
模式[lcr]
類型string
op
模式T
類型string
pt
$ref#/definitions/point
width
類型數字
point
最小項目數2
項目
類型數字
類型陣列
最大項目數2
停止
必要
  • 分數
  • color
類型物件
屬性
color
$ref#/definitions/color
分數
類型數字
繪圖顏色
必要
  • op
  • grad
類型物件
屬性
p0
oneOf
$ref
#/definitions/point
#/definitions/point3
p1
oneOf
$ref
#/definitions/point
#/definitions/point3
color
$ref#/definitions/color
停止
項目
$ref#/definitions/stop
類型陣列
grad
枚舉
  • 線性
  • 放射狀
類型string
op
模式[cC]
類型string
橢圓形
必要
  • op
  • rect
類型物件
屬性
rect
$ref#/definitions/rectangle
op
模式[eE]
類型string
貝茲曲線
必要
  • op
類型物件
屬性
$ref#/definitions/pointlist
op
模式[bB]
類型string
邊緣
必要
  • _gvid
  • 尾部
  • 頭部
類型物件
屬性
_hldraw_
$ref#/definitions/drawops
_tdraw_
$ref#/definitions/drawops
_draw_
$ref#/definitions/drawops
_ldraw_
$ref#/definitions/drawops
_gvid
類型整數
尾部
類型整數
描述尾部節點的 _gvid
_tldraw_
$ref#/definitions/drawops
_hdraw_
$ref#/definitions/drawops
additionalProperties
類型string
頭部
類型整數
描述尾部頭部的 _gvid
標題邊緣
折線
必要
  • op
類型物件
屬性
$ref#/definitions/pointlist
op
模式L
類型string
字型
必要
  • op
  • size
類型物件
屬性
size
最小值0
類型數字
op
模式F
類型string
類型string
點3
最小項目數3
項目
類型數字
類型陣列
最大項目數3
矩形
最小項目數4
項目
類型數字
類型陣列
最大項目數4
點列表
項目
$ref#/definitions/point
類型陣列
類型物件
屬性
定向
類型布林值
描述如果圖形是有向的,則為 True
_draw_
$ref#/definitions/drawops
名稱
類型string
描述圖形名稱
物件
項目
$ref#/definitions/metanode
類型陣列
描述圖形的子圖,後接圖形的節點
_ldraw_
$ref#/definitions/drawops
嚴格
類型布林值
描述如果圖形是嚴格的,則為 True
邊緣
項目
$ref#/definitions/edge
類型陣列
additionalProperties
類型string
_subgraph_cnt
類型整數
描述圖形中子圖的數量
上次修改時間:2024 年 7 月 28 日:將所有 Hugo 'ref' 取代為 'relref's (bbef86a)