Nesting metadata
A walk-through on creating nested metadata structures
Object blocks
Nesting is supported by structuring metadata with Object blocks.
All Object blocks must have a string
property, which is the text content of the block. This is true regardless of the nesting level of the Object. If it doesn't exist, an error will be thrown.
Object blocks can also have an (optional) children
property, which enables nesting. Whereas String blocks are always childless, Object blocks can have descendants through their children
property - an Array which can contain String blocks as well as Object blocks. The contents of the children
array will be processed and added under the parent block.
Processing order for nested blocks
Items are processed recursively, and blocks are added one-by-one to ensure they are in the right order on the page. This means that, for a given Object block, all of the block's descendants will be added before the block's next sibling (if applicable) is added.
It also means that multi-level nesting is possible, with as many levels as desired. Do make sure that every Object block in the path is properly structured, and be careful to check that elements are the right type : string
should always be a String ; children
should always be an Array, where each element is either a String or an Object block.
Creating formatting functions for nested output
When creating a nested output, the formatting function must still return an array of metadata ; its elements can be all Object blocks, or a mix of String blocks and Object blocks. Make sure that the children
property is always an Array, even if it has only one element in it (or if it's empty).
To help you with writing your own functions, I've made an Observable interactive notebook, where you can try your hand at writing functions & using them to process your own Zotero data :
Examples of output
One level of nesting
Multi-level nesting.
Last updated