JSON Canvas Skill
File Structure
A canvas file (.canvas) contains two top-level arrays following the JSON Canvas Spec 1.0:
{
"nodes": [],
"edges": []
}
nodes (optional): Array of node objects
edges (optional): Array of edge objects connecting nodes
Common Workflows
1. Create a New Canvas
- Create a
.canvas file with the base structure {"nodes": [], "edges": []}
- Generate unique 16-character hex IDs for each node (e.g.,
"6f0ad84f44ce9c17")
- Add nodes with required fields:
id, type, x, y, width, height
- Add edges referencing valid node IDs via
fromNode and toNode
- Validate: Parse the JSON to confirm it is valid. Verify all
fromNode/toNode values exist in the nodes array
2. Add a Node to an Existing Canvas
- Read and parse the existing
.canvas file
- Generate a unique ID that does not collide with existing node or edge IDs
- Choose position (
x, y) that avoids overlapping existing nodes (leave 50-100px spacing)
- Append the new node object to the
nodes array
- Optionally add edges connecting the new node to existing nodes
- Validate: Confirm all IDs are unique and all edge references resolve to existing nodes
3. Connect Two Nodes
- Identify the source and target node IDs
- Generate a unique edge ID
- Set
fromNode and toNode to the source and target IDs
- Optionally set
fromSide/toSide (top, right, bottom, left) for anchor points
- Optionally set
label for descriptive text on the edge
- Append the edge to the
edges array
- Validate: Confirm both
fromNode and toNode reference existing node IDs
4. Edit an Existing Canvas
- Read and parse the
.canvas file as JSON
- Locate the target node or edge by
id
- Modify the desired attributes (text, position, color, etc.) while preserving fields you do not need to change
- Write the updated JSON back to the file with stable formatting: 2-space indentation and a trailing newline
- Validate: Re-check all ID uniqueness and edge reference integrity after editing
Working Rules
- Preserve unknown node or edge fields instead of deleting them; some apps and plugins add extension metadata
- Keep existing IDs stable unless the task explicitly requires replacing a node or edge
- Prefer minimally invasive edits when modifying an existing canvas
- When generating a new canvas from notes or an outline, convert major sections into nodes first, then add groups and edges only if they make the structure clearer
- When the request is in Chinese, keep the canvas content in the user's language unless they ask for translation
Nodes
Nodes are objects placed on the canvas. Array order determines z-index: first node = bottom layer, last node = top layer.
Generic Node Attributes
| Attribute |
Required |
Type |
Description |
id |
Yes |
string |
Unique 16-char hex identifier |
type |
Yes |
string |
text, file, link, or group |
x |
Yes |
integer |
X position in pixels |
y |
Yes |
integer |
Y position in pixels |
width |
Yes |
integer |
Width in pixels |
height |
Yes |
integer |
Height in pixels |
color |
No |
canvasColor |
Preset "1"-"6" or hex (e.g., "#FF0000") |
Text Nodes
| Attribute |
Required |
Type |
Description |
text |
Yes |
string |
Plain text with Markdown syntax |
{
"id": "6f0ad84f44ce9c17",
"type": "text",
"x": 0,
"y": 0,
"width": 400,
"height": 200,
"text": "# Hello World\n\nThis is **Markdown** content."
}
Newline pitfall: Use \n for line breaks in JSON strings. Do not use the literal \\n -- Obsidian renders that as the characters \ and n.
File Nodes
| Attribute |
Required |
Type |
Description |
file |
Yes |
string |
Path to file within the system |
subpath |
No |
string |
Link to heading or block (starts with #) |
{
"id": "a1b2c3d4e5f67890",
"type": "file",
"x": 500,
"y": 0,
"width": 400,
"height": 300,
"file": "Attachments/diagram.png"
}
Link Nodes
| Attribute |
Required |
Type |
Description |
url |
Yes |
string |
External URL |
{
"id": "c3d4e5f678901234",
"type": "link",
"x": 1000,
"y": 0,
"width": 400,
"height": 200,
"url": "https://obsidian.md"
}
Group Nodes
Groups are visual containers for organizing other nodes. Position child nodes inside the group's bounds.
| Attribute |
Required |
Type |
Description |
label |
No |
string |
Text label for the group |
background |
No |
string |
Path to background image |
backgroundStyle |
No |
string |
cover, ratio, or repeat |
{
"id": "d4e5f6789012345a",
"type": "group",
"x": -50,
"y": -50,
"width": 1000,
"height": 600,
"label": "Project Overview",
"color": "4"
}
Edges
Edges connect nodes via fromNode and toNode IDs.
| Attribute |
Required |
Type |
Default |
Description |
id |
Yes |
string |
- |
Unique identifier |
fromNode |
Yes |
string |
- |
Source node ID |
fromSide |
No |
string |
- |
top, right, bottom, or left |
fromEnd |
No |
string |
none |
none or arrow |
toNode |
Yes |
string |
- |
Target node ID |
toSide |
No |
string |
- |
top, right, bottom, or left |
toEnd |
No |
string |
arrow |
none or arrow |
color |
No |
canvasColor |
- |
Line color |
label |
No |
string |
- |
Text label |
{
"id": "0123456789abcdef",
"fromNode": "6f0ad84f44ce9c17",
"fromSide": "right",
"toNode": "a1b2c3d4e5f67890",
"toSide": "left",
"toEnd": "arrow",
"label": "leads to"
}
Colors
The canvasColor type accepts either a hex string or a preset number:
| Preset |
Color |
"1" |
Red |
"2" |
Orange |
"3" |
Yellow |
"4" |
Green |
"5" |
Cyan |
"6" |
Purple |
Preset color values are intentionally undefined -- applications use their own brand colors.
ID Generation
Generate 16-character lowercase hexadecimal strings (64-bit random value):
"6f0ad84f44ce9c17"
"a3b2c1d0e9f8a7b6"
Layout Guidelines
- Coordinates can be negative (canvas extends infinitely)
x increases right, y increases down; position is the top-left corner
- Space nodes 50-100px apart; leave 20-50px padding inside groups
- Align to grid (multiples of 10 or 20) for cleaner layouts
| Node Type |
Suggested Width |
Suggested Height |
| Small text |
200-300 |
80-150 |
| Medium text |
300-450 |
150-300 |
| Large text |
400-600 |
300-500 |
| File preview |
300-500 |
200-400 |
| Link preview |
250-400 |
100-200 |
Validation Checklist
After creating or editing a canvas file, verify:
- All
id values are unique across both nodes and edges
- Every
fromNode and toNode references an existing node ID
- Required fields are present for each node type (
text for text nodes, file for file nodes, url for link nodes)
type is one of: text, file, link, group
fromSide/toSide values are one of: top, right, bottom, left
fromEnd/toEnd values are one of: none, arrow
- Color presets are
"1" through "6" or valid hex (e.g., "#FF0000")
- JSON is valid and parseable
If validation fails, check for duplicate IDs, dangling edge references, or malformed JSON strings (especially unescaped newlines in text content).
Complete Examples
See references/EXAMPLES.md for full canvas examples including mind maps, project boards, research canvases, and flowcharts.
References
1---2name: json-canvas3description: Create and edit JSON Canvas files (.canvas) with nodes, edges, groups, and connections. Use when working with .canvas files, Obsidian Canvas, JSON Canvas, visual canvases, whiteboards, mind maps, flowcharts, concept maps, or research boards, including Chinese requests that mention 画布, 白板, 思维导图, 流程图, or Obsidian 画布.4---56# JSON Canvas Skill78## File Structure910A canvas file (`.canvas`) contains two top-level arrays following the [JSON Canvas Spec 1.0](https://jsoncanvas.org/spec/1.0/):1112```json13{14 "nodes": [],15 "edges": []16}17```1819- `nodes` (optional): Array of node objects20- `edges` (optional): Array of edge objects connecting nodes2122## Common Workflows2324### 1. Create a New Canvas25261. Create a `.canvas` file with the base structure `{"nodes": [], "edges": []}`272. Generate unique 16-character hex IDs for each node (e.g., `"6f0ad84f44ce9c17"`)283. Add nodes with required fields: `id`, `type`, `x`, `y`, `width`, `height`294. Add edges referencing valid node IDs via `fromNode` and `toNode`305. **Validate**: Parse the JSON to confirm it is valid. Verify all `fromNode`/`toNode` values exist in the nodes array3132### 2. Add a Node to an Existing Canvas33341. Read and parse the existing `.canvas` file352. Generate a unique ID that does not collide with existing node or edge IDs363. Choose position (`x`, `y`) that avoids overlapping existing nodes (leave 50-100px spacing)374. Append the new node object to the `nodes` array385. Optionally add edges connecting the new node to existing nodes396. **Validate**: Confirm all IDs are unique and all edge references resolve to existing nodes4041### 3. Connect Two Nodes42431. Identify the source and target node IDs442. Generate a unique edge ID453. Set `fromNode` and `toNode` to the source and target IDs464. Optionally set `fromSide`/`toSide` (top, right, bottom, left) for anchor points475. Optionally set `label` for descriptive text on the edge486. Append the edge to the `edges` array497. **Validate**: Confirm both `fromNode` and `toNode` reference existing node IDs5051### 4. Edit an Existing Canvas52531. Read and parse the `.canvas` file as JSON542. Locate the target node or edge by `id`553. Modify the desired attributes (text, position, color, etc.) while preserving fields you do not need to change564. Write the updated JSON back to the file with stable formatting: 2-space indentation and a trailing newline575. **Validate**: Re-check all ID uniqueness and edge reference integrity after editing5859## Working Rules6061- Preserve unknown node or edge fields instead of deleting them; some apps and plugins add extension metadata62- Keep existing IDs stable unless the task explicitly requires replacing a node or edge63- Prefer minimally invasive edits when modifying an existing canvas64- When generating a new canvas from notes or an outline, convert major sections into nodes first, then add groups and edges only if they make the structure clearer65- When the request is in Chinese, keep the canvas content in the user's language unless they ask for translation6667## Nodes6869Nodes are objects placed on the canvas. Array order determines z-index: first node = bottom layer, last node = top layer.7071### Generic Node Attributes7273| Attribute | Required | Type | Description |74|-----------|----------|------|-------------|75| `id` | Yes | string | Unique 16-char hex identifier |76| `type` | Yes | string | `text`, `file`, `link`, or `group` |77| `x` | Yes | integer | X position in pixels |78| `y` | Yes | integer | Y position in pixels |79| `width` | Yes | integer | Width in pixels |80| `height` | Yes | integer | Height in pixels |81| `color` | No | canvasColor | Preset `"1"`-`"6"` or hex (e.g., `"#FF0000"`) |8283### Text Nodes8485| Attribute | Required | Type | Description |86|-----------|----------|------|-------------|87| `text` | Yes | string | Plain text with Markdown syntax |8889```json90{91 "id": "6f0ad84f44ce9c17",92 "type": "text",93 "x": 0,94 "y": 0,95 "width": 400,96 "height": 200,97 "text": "# Hello World\n\nThis is **Markdown** content."98}99```100101**Newline pitfall**: Use `\n` for line breaks in JSON strings. Do **not** use the literal `\\n` -- Obsidian renders that as the characters `\` and `n`.102103### File Nodes104105| Attribute | Required | Type | Description |106|-----------|----------|------|-------------|107| `file` | Yes | string | Path to file within the system |108| `subpath` | No | string | Link to heading or block (starts with `#`) |109110```json111{112 "id": "a1b2c3d4e5f67890",113 "type": "file",114 "x": 500,115 "y": 0,116 "width": 400,117 "height": 300,118 "file": "Attachments/diagram.png"119}120```121122### Link Nodes123124| Attribute | Required | Type | Description |125|-----------|----------|------|-------------|126| `url` | Yes | string | External URL |127128```json129{130 "id": "c3d4e5f678901234",131 "type": "link",132 "x": 1000,133 "y": 0,134 "width": 400,135 "height": 200,136 "url": "https://obsidian.md"137}138```139140### Group Nodes141142Groups are visual containers for organizing other nodes. Position child nodes inside the group's bounds.143144| Attribute | Required | Type | Description |145|-----------|----------|------|-------------|146| `label` | No | string | Text label for the group |147| `background` | No | string | Path to background image |148| `backgroundStyle` | No | string | `cover`, `ratio`, or `repeat` |149150```json151{152 "id": "d4e5f6789012345a",153 "type": "group",154 "x": -50,155 "y": -50,156 "width": 1000,157 "height": 600,158 "label": "Project Overview",159 "color": "4"160}161```162163## Edges164165Edges connect nodes via `fromNode` and `toNode` IDs.166167| Attribute | Required | Type | Default | Description |168|-----------|----------|------|---------|-------------|169| `id` | Yes | string | - | Unique identifier |170| `fromNode` | Yes | string | - | Source node ID |171| `fromSide` | No | string | - | `top`, `right`, `bottom`, or `left` |172| `fromEnd` | No | string | `none` | `none` or `arrow` |173| `toNode` | Yes | string | - | Target node ID |174| `toSide` | No | string | - | `top`, `right`, `bottom`, or `left` |175| `toEnd` | No | string | `arrow` | `none` or `arrow` |176| `color` | No | canvasColor | - | Line color |177| `label` | No | string | - | Text label |178179```json180{181 "id": "0123456789abcdef",182 "fromNode": "6f0ad84f44ce9c17",183 "fromSide": "right",184 "toNode": "a1b2c3d4e5f67890",185 "toSide": "left",186 "toEnd": "arrow",187 "label": "leads to"188}189```190191## Colors192193The `canvasColor` type accepts either a hex string or a preset number:194195| Preset | Color |196|--------|-------|197| `"1"` | Red |198| `"2"` | Orange |199| `"3"` | Yellow |200| `"4"` | Green |201| `"5"` | Cyan |202| `"6"` | Purple |203204Preset color values are intentionally undefined -- applications use their own brand colors.205206## ID Generation207208Generate 16-character lowercase hexadecimal strings (64-bit random value):209210```211"6f0ad84f44ce9c17"212"a3b2c1d0e9f8a7b6"213```214215## Layout Guidelines216217- Coordinates can be negative (canvas extends infinitely)218- `x` increases right, `y` increases down; position is the top-left corner219- Space nodes 50-100px apart; leave 20-50px padding inside groups220- Align to grid (multiples of 10 or 20) for cleaner layouts221222| Node Type | Suggested Width | Suggested Height |223|-----------|-----------------|------------------|224| Small text | 200-300 | 80-150 |225| Medium text | 300-450 | 150-300 |226| Large text | 400-600 | 300-500 |227| File preview | 300-500 | 200-400 |228| Link preview | 250-400 | 100-200 |229230## Validation Checklist231232After creating or editing a canvas file, verify:2332341. All `id` values are unique across both nodes and edges2352. Every `fromNode` and `toNode` references an existing node ID2363. Required fields are present for each node type (`text` for text nodes, `file` for file nodes, `url` for link nodes)2374. `type` is one of: `text`, `file`, `link`, `group`2385. `fromSide`/`toSide` values are one of: `top`, `right`, `bottom`, `left`2396. `fromEnd`/`toEnd` values are one of: `none`, `arrow`2407. Color presets are `"1"` through `"6"` or valid hex (e.g., `"#FF0000"`)2418. JSON is valid and parseable242243If validation fails, check for duplicate IDs, dangling edge references, or malformed JSON strings (especially unescaped newlines in text content).244245## Complete Examples246247See [references/EXAMPLES.md](references/EXAMPLES.md) for full canvas examples including mind maps, project boards, research canvases, and flowcharts.248249## References250251- [JSON Canvas Spec 1.0](https://jsoncanvas.org/spec/1.0/)252- [JSON Canvas GitHub](https://github.com/obsidianmd/jsoncanvas)