JSON Canvas Spec
The JSON Canvas Spec introduces a standardized, open format for representing visual canvases through nodes and edges. This technical deep dive outlines a flexible way to define interactive diagrams, mind maps, or visual notes using a simple JSON structure. Developers on Hacker News appreciate new, well-defined data interchange formats that promise interoperability and ease of implementation for visual applications.
The Lowdown
The JSON Canvas Specification (Version 1.0) defines a structured, open format for representing visual canvases, comprising interconnected nodes and edges. This spec aims to provide a common, interoperable language for various canvas-based applications, allowing for consistent data representation and exchange.
- Top-Level Structure: A JSON Canvas document consists of two optional arrays:
nodesandedges. - Nodes: Represent objects on the canvas, ordered by z-index (first node is lowest). All nodes share required attributes like
id,type,x,y,width,height, and an optionalcolor.- Text Nodes: Store plain text, supporting Markdown syntax via a
textattribute. - File Nodes: Reference external files or attachments using a
filepath and an optionalsubpath(e.g.,#heading). - Link Nodes: Point to a URL using a
urlattribute. - Group Nodes: Act as visual containers, featuring optional
label,backgroundimage path, andbackgroundStyle(cover,ratio,repeat).
- Text Nodes: Store plain text, supporting Markdown syntax via a
- Edges: Define connections between nodes with required
id,fromNode, andtoNodeattributes. They also support optionalfromSide/toSide(top, right, bottom, left),fromEnd/toEndshapes (none, arrow),color, and alabel. - Color Specification: Uses a
canvasColortype, allowing hex codes (e.g.,"#FF0000") or six preset numerical values ("1"-"6" for red, orange, yellow, green, cyan, purple). The exact values for preset colors are intentionally undefined, allowing applications to customize them.
This specification provides a foundational framework for developers to build and share complex visual layouts, ensuring that canvas data can be understood and rendered consistently across different tools and platforms.