8 ms·
An object in JSON is meant to be unordered [1], so arrays are better if you want order to be preserved. [1] https://www.json.org/json-en.html https://www.json.
by desmondl 3y ago
An object in JSON is meant to be unordered [1], so arrays are better if you want order to be preserved.
[1] https://www.json.org/json-en.html https://www.json.org/json-en.html
- Retr0id 3y agoSure, but why do you want order to be preserved? The spec never says the order of nodes is pertinent. Is there undocumented z-index behavior?
- Retr0id 3y agoLooking at their reference impl, it does seem that array index implies z-index, in which case fair enough, I suppose an array does make the most sense - they should probably document the z-indexing though!
- desmondl 3y agoSometimes you have nodes that overlap each other, so you want to control whether or not a node is in front of or behind another node. Though yes, they could have explicitly defined a z-index or defined a convention on how the ordering should work (first nodes top and last nodes bottom or vice versa?). It's interesting to think about the trade offs between explicitly defining these things vs. leaving the application to implicitly make the choice. JSON Canvas seems to be designed to use in tandem with markdown files in a note taking app, so it makes sense why they opted for the more implicit design to be similar to markdown
- kepano 3y agoThis clarification has been added to the spec: > Nodes are placed in the array in ascending order by z-index. The first node in the array should be displayed below all other nodes, and the last node in the array should be displayed on top of all other nodes.