generate¶
Create D2 code from structured TOON, JSON, or YAML specifications.
Usage¶
Flags¶
| Flag | Default | Description |
|---|---|---|
-f, --format |
auto-detect | Input format: toon, json, yaml |
Input Schema¶
The DiagramSpec structure defines the diagram:
# Layout settings (optional)
direction: right # right, down, left, up
gridColumns: 2 # Force grid layout
gridRows: 2
# Top-level nodes
nodes:
- id: external
label: External Service
shape: cloud
# Containers (clusters/boundaries)
containers:
- id: cluster1
label: Cluster 1
direction: down
style:
fill: "#f0f0f0"
nodes:
- id: service1
label: Service 1
- id: db1
label: Database
shape: cylinder
edges:
- from: service1
to: db1
# Cross-container edges
edges:
- from: cluster1.db1
to: external
label: syncs
Examples¶
Generate from TOON¶
Generate from JSON¶
Pipe from stdin¶
Full Pipeline¶
From Template¶
# Get template, modify, generate
d2vision template network-boundary > spec.toon
# ... edit spec.toon ...
d2vision generate spec.toon | d2 - output.svg
Supported Features¶
Shapes¶
rectangle(default)squarecircleovaldiamondhexagoncylinderqueuepagedocumentpersoncloud
Styles¶
Special Diagrams¶
Sequence diagrams and SQL tables are also supported: