document.json instead of document.md.
Writing JSON Directly
The simplest approach is writing JSON directly. If your entire document is valid JSON, Colin passes it through:tojson filter to ensure proper escaping:
JSON Fences
The recommended approach is wrapping your JSON in a code fence. Colin validates the syntax and provides clear error messages if something is malformed:Markdown Structure
Writing JSON in templates gets painful fast. Consider generating a list of users:Headers as Keys
Each header becomes an object key. Text content under the header becomes a string value:Lists as Arrays
Markdown lists under a header become JSON arrays:Literal Values
Text under headers is parsed as strings. For numbers, booleans, or complex objects, use a JSON fence. You can use JSON fences anywhere within a markdown-structured document to write literal JSON as a value:Nested Objects
Deeper header levels create nested objects. An## header containing ### headers becomes a nested structure:
_content key:
Array Elements
Colin provides a custom{% item %}...{% enditem %} block for creating array elements. Combined with loops, this generates arrays of objects:
{% item %} block becomes one element in the output array. Items can contain full markdown structure including nested headers and lists.
Validation
The renderer enforces several rules:| Rule | Behavior |
|---|---|
| Duplicate keys at same level | Error |
| Content before first header | Error |
{% item %} before headers at root | Error |
| Invalid JSON in fence | Error with location |
| No structure detected | Warning, returns string |