JSON Canvas Skill
File Structure
A canvas file (.canvas) contains two top-level arrays following the JSON Canvas Spec 1.0:
{
"nodes": [],
"edges": []
}
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: 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 IDs
- Choose position (
x, y) that avoids overlapping existing nodes (50-100px spacing)
- Append the new node object to the
nodes array
- Validate: Confirm all IDs are unique and all edge references resolve
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) and label
- Validate: Confirm both IDs reference existing nodes
Nodes
Nodes are objects placed on the canvas. Array order determines z-index (first = bottom 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 |
string |
Preset "1"-"6" or hex (e.g., "#FF0000") |
Text Node
{
"id": "6f0ad84f44ce9c17",
"type": "text",
"x": 0, "y": 0, "width": 400, "height": 200,
"text": "# Hello World\n\nThis is **Markdown** content."
}
Newline pitfall: Use \n in JSON strings. Do not use literal \\n.
File Node
{
"id": "a1b2c3d4e5f67890",
"type": "file",
"x": 500, "y": 0, "width": 400, "height": 300,
"file": "Attachments/diagram.png"
}
Link Node
{
"id": "c3d4e5f678901234",
"type": "link",
"x": 1000, "y": 0, "width": 400, "height": 200,
"url": "https://obsidian.md"
}
Group Node
{
"id": "d4e5f6789012345a",
"type": "group",
"x": -50, "y": -50, "width": 1000, "height": 600,
"label": "Project Overview",
"color": "4"
}
Edges
| Attribute |
Required |
Default |
Description |
id |
Yes |
- |
Unique identifier |
fromNode |
Yes |
- |
Source node ID |
toNode |
Yes |
- |
Target node ID |
fromSide |
No |
- |
top, right, bottom, or left |
toSide |
No |
- |
top, right, bottom, or left |
fromEnd |
No |
none |
none or arrow |
toEnd |
No |
arrow |
none or arrow |
color |
No |
- |
Line color |
label |
No |
- |
Text label |
{
"id": "0123456789abcdef",
"fromNode": "6f0ad84f44ce9c17",
"fromSide": "right",
"toNode": "a1b2c3d4e5f67890",
"toSide": "left",
"label": "leads to"
}
Colors
| Preset |
Color |
"1" |
Red |
"2" |
Orange |
"3" |
Yellow |
"4" |
Green |
"5" |
Cyan |
"6" |
Purple |
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 |
Validation Checklist
After creating or editing a canvas file:
- 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
type is one of: text, file, link, group
- Side values are one of:
top, right, bottom, left
- End values are one of:
none, arrow
- JSON is valid and parseable
References
1---2name: json-canvas3description: Create and edit JSON Canvas files (.canvas) with nodes, edges, groups, and connections. Use when working with .canvas files, creating visual canvases, mind maps, flowcharts, or when the user mentions Canvas files in 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## Common Workflows2021### 1. Create a New Canvas22231. Create a `.canvas` file with the base structure `{"nodes": [], "edges": []}`242. Generate unique 16-character hex IDs for each node (e.g., `"6f0ad84f44ce9c17"`)253. Add nodes with required fields: `id`, `type`, `x`, `y`, `width`, `height`264. Add edges referencing valid node IDs via `fromNode` and `toNode`275. **Validate**: Verify all `fromNode`/`toNode` values exist in the nodes array2829### 2. Add a Node to an Existing Canvas30311. Read and parse the existing `.canvas` file322. Generate a unique ID that does not collide with existing IDs333. Choose position (`x`, `y`) that avoids overlapping existing nodes (50-100px spacing)344. Append the new node object to the `nodes` array355. **Validate**: Confirm all IDs are unique and all edge references resolve3637### 3. Connect Two Nodes38391. Identify the source and target node IDs402. Generate a unique edge ID413. Set `fromNode` and `toNode` to the source and target IDs424. Optionally set `fromSide`/`toSide` (`top`, `right`, `bottom`, `left`) and `label`435. **Validate**: Confirm both IDs reference existing nodes4445## Nodes4647Nodes are objects placed on the canvas. Array order determines z-index (first = bottom layer).4849### Generic Node Attributes5051| Attribute | Required | Type | Description |52|-----------|----------|------|-------------|53| `id` | Yes | string | Unique 16-char hex identifier |54| `type` | Yes | string | `text`, `file`, `link`, or `group` |55| `x` | Yes | integer | X position in pixels |56| `y` | Yes | integer | Y position in pixels |57| `width` | Yes | integer | Width in pixels |58| `height` | Yes | integer | Height in pixels |59| `color` | No | string | Preset `"1"`-`"6"` or hex (e.g., `"#FF0000"`) |6061### Text Node6263```json64{65 "id": "6f0ad84f44ce9c17",66 "type": "text",67 "x": 0, "y": 0, "width": 400, "height": 200,68 "text": "# Hello World\n\nThis is **Markdown** content."69}70```7172**Newline pitfall**: Use `\n` in JSON strings. Do **not** use literal `\\n`.7374### File Node7576```json77{78 "id": "a1b2c3d4e5f67890",79 "type": "file",80 "x": 500, "y": 0, "width": 400, "height": 300,81 "file": "Attachments/diagram.png"82}83```8485### Link Node8687```json88{89 "id": "c3d4e5f678901234",90 "type": "link",91 "x": 1000, "y": 0, "width": 400, "height": 200,92 "url": "https://obsidian.md"93}94```9596### Group Node9798```json99{100 "id": "d4e5f6789012345a",101 "type": "group",102 "x": -50, "y": -50, "width": 1000, "height": 600,103 "label": "Project Overview",104 "color": "4"105}106```107108## Edges109110| Attribute | Required | Default | Description |111|-----------|----------|---------|-------------|112| `id` | Yes | - | Unique identifier |113| `fromNode` | Yes | - | Source node ID |114| `toNode` | Yes | - | Target node ID |115| `fromSide` | No | - | `top`, `right`, `bottom`, or `left` |116| `toSide` | No | - | `top`, `right`, `bottom`, or `left` |117| `fromEnd` | No | `none` | `none` or `arrow` |118| `toEnd` | No | `arrow` | `none` or `arrow` |119| `color` | No | - | Line color |120| `label` | No | - | Text label |121122```json123{124 "id": "0123456789abcdef",125 "fromNode": "6f0ad84f44ce9c17",126 "fromSide": "right",127 "toNode": "a1b2c3d4e5f67890",128 "toSide": "left",129 "label": "leads to"130}131```132133## Colors134135| Preset | Color |136|--------|-------|137| `"1"` | Red |138| `"2"` | Orange |139| `"3"` | Yellow |140| `"4"` | Green |141| `"5"` | Cyan |142| `"6"` | Purple |143144## Layout Guidelines145146- Coordinates can be negative (canvas extends infinitely)147- `x` increases right, `y` increases down; position is the top-left corner148- Space nodes 50-100px apart; leave 20-50px padding inside groups149- Align to grid (multiples of 10 or 20) for cleaner layouts150151| Node Type | Suggested Width | Suggested Height |152|-----------|-----------------|------------------|153| Small text | 200-300 | 80-150 |154| Medium text | 300-450 | 150-300 |155| Large text | 400-600 | 300-500 |156157## Validation Checklist158159After creating or editing a canvas file:1601611. All `id` values are unique across both nodes and edges1622. Every `fromNode` and `toNode` references an existing node ID1633. Required fields are present for each node type1644. `type` is one of: `text`, `file`, `link`, `group`1655. Side values are one of: `top`, `right`, `bottom`, `left`1666. End values are one of: `none`, `arrow`1677. JSON is valid and parseable168169## References170171- [JSON Canvas Spec 1.0](https://jsoncanvas.org/spec/1.0/)172- [JSON Canvas GitHub](https://github.com/obsidianmd/jsoncanvas)