Data Source
The source property populates tables and lists from arrays in your data object. This is how you generate dynamic-length content -- tables with a variable number of rows, or lists with a variable number of items.
Table data source
Properties
| Property | Type | Description |
|---|---|---|
source | string | $data path pointing to an array of objects |
map | string[] | Array of object keys, mapped to columns left-to-right |
How it works
- Define the table with its
widthsand a header row inrows. - Set
sourceto a$datapath pointing to an array of objects. - Set
mapto specify which object keys map to which columns. - At generation time, one row is appended for each item in the array, with values pulled from the keys listed in
map.
The header row you define in rows is preserved. Data rows are appended after it.
Template
{
"table": {
"source": "$data.items",
"map": ["description", "qty", "amount"],
"widths": [3, 1, 1],
"rows": [
[
{ "p": "[b]Description[/b]" },
{ "p": "[b]Qty[/b]" },
{ "p": "[b]Amount[/b]" }
]
]
}
}
Data
{
"items": [
{ "description": "Cloud migration", "qty": "120", "amount": "$18,000" },
{ "description": "Security audit", "qty": "40", "amount": "$6,000" },
{ "description": "Training sessions", "qty": "16", "amount": "$2,400" }
]
}
Result
The table renders with the header row plus three data rows:
| Description | Qty | Amount |
|---|---|---|
| Cloud migration | 120 | $18,000 |
| Security audit | 40 | $6,000 |
| Training sessions | 16 | $2,400 |
Column mapping
The map array maps object keys to columns positionally:
map[0]maps to the first columnmap[1]maps to the second columnmap[2]maps to the third column
The number of entries in map should match the number of columns defined in widths.
A map entry is a property name, or a template holding $item tokens, which may mix in $data ones:
"$item.qty x $item.unit", "$item.amount $data.currency". A property whose value is an object or an array has no
text: its cell is left empty and the report names the property.
Arrays that are not objects
Without map, a source of arrays draws each inner array as a row, cell by cell, and a source of strings or numbers
draws one single-cell row per value:
{
"table": {
"source": "$data.matrix",
"widths": [1, 1],
"rows": [
[{ "th": "Region" }, { "th": "Units" }]
]
}
}
With { "matrix": [["North", "1,200"], ["South", "950"]] }, the table draws its header and two rows.
Template rows and items
The other way to bind a container is to write the row, or the list item, that repeats: any row of a bound table, and
any li of a bound list, that carries an $item token is a template, drawn once per element of the source, in
place. A row or item without one is literal and is drawn once, where it stands. A template row is a full row, so a
generated cell keeps its own style, colspan, image or th, which a map cell cannot.
{
"table": {
"source": "$data.items",
"widths": [1, 4, 2],
"rows": [
[{ "th": "#" }, { "th": "Description" }, { "th": "Amount" }],
[{ "p": "$item.NUMBER" }, { "p": "$item.description" }, { "p": "$item.amount", "style": "$item.tone" }],
[{ "p": "$item.COUNT lines", "colspan": 3 }]
]
}
}
| Token | What it reads |
|---|---|
$item.name | a property of the element; digit segments index arrays, as in $data paths ($item.lines.0.sku) |
$item | the element itself, for a source of strings or numbers. An object or an array has no text form: it places nothing and is reported |
$item.NUMBER | the element's position, counting from 1 |
$item.COUNT | the number of elements in the source; it also resolves in a literal row, which is how a summary row says "3 lines" |
NUMBER and COUNT are reserved in upper case only: $item.count reads the element's own count. An element that has
a NUMBER or COUNT property cannot reach it through $item, and the report says so.
Consecutive template rows repeat together as one group, element by element, so a group header row followed by its detail
row stays one unit. A node's style takes tokens too, so "style": "$item.tone" lets each element choose its style.
map and a template row in one container are two spellings of the same repetition: the container is refused with an
error that asks you to keep the row and drop map.
Nested sources
Inside a template, a container's source may be an $item path, so each element binds a list or a table of its own.
The innermost binding is what $item reads:
{
"ul": {
"source": "$data.groups",
"li": [
{ "p": "[b]$item.title[/b]" },
{ "ul": { "source": "$item.children", "li": [{ "p": "$item" }] } }
]
}
}
With { "groups": [{ "title": "Hardware", "children": ["Laptop", "Dock"] }, { "title": "Software", "children": ["Licence"] }] },
each group's title is followed by its own nested list.
Empty and missing sources
| Source resolves to | Template rows or items | map, or no template |
|---|---|---|
| an array with elements | one copy per element | one row or item per element |
| an empty array | literal rows are drawn once, template rows zero times, $item.COUNT is 0; nothing is reported | nothing is added, and the report says the source has no items |
| nothing, or not an array | the rows and items stay as written, so the report names each $item token left standing, and says the source has no items | nothing is added, and the report says the source has no items |
An empty array is legal data (an invoice with no line items), so keep a literal header row in a table whose rows are all templates: a table left with no row at all is not a table.
Limits
Binding repeats nodes, and repetition multiplies: a list of ten bound five deep in itself is more than 100,000 items. A
document may add at most 250,000 content nodes through source; past that, the document is refused with
CONTENT_TOO_LARGE. See Limits.
List data source
A data-driven list uses source (and optionally map). For an array of strings, each string becomes a list item directly. For an array of objects, supply map with a $item.* template.
Properties
| Property | Type | Description |
|---|---|---|
source | string | $data path pointing to an array |
map | string | Optional template for each item (e.g. "$item.name — $item.role") |
How it works
- Define the list (
ulorol) withsourceinside it. - Set
sourceto a$datapath pointing to an array. - At generation time, one list item is created for each entry in the array.
When source is supplied, li may be omitted — the items are produced from the data. An li item that carries $item tokens is a template, repeated once per element of the array; an li item without one is literal and stays where it is, once.
Unordered list
{
"ul": {
"source": "$data.notes"
}
}
Ordered list
{
"ol": {
"source": "$data.paymentTerms"
}
}
Data
{
"notes": [
"Payment due within 30 days",
"Late fees apply after due date",
"Contact billing@acme.com for questions"
],
"paymentTerms": [
"Wire transfer to ShipForge Ltd account",
"Reference: INV-SF-2026-0329",
"Net 30 days from invoice date"
]
}
Combined example: table and list
This example uses both a table source for line items and a list source for payment terms in a single document.
Template
{
"document": {
"styles": {
"title": { "fontSize": 20, "fontWeight": "bold" },
"subtitle": { "fontSize": 12, "fontStyle": "italic", "color": "#555555" },
"total": { "fontWeight": "bold", "fontSize": 14 }
},
"content": [
{ "p": "$data.document.title", "style": "title" },
{ "p": "Prepared for $data.client.companyName on $data.document.date", "style": "subtitle" },
{
"hr": {
"borderStyle": "solid",
"height": 1,
"color": "#000000"
}
},
{
"table": {
"source": "$data.lineItems",
"map": ["service", "hours", "rate", "total"],
"widths": [4, 1, 1, 1],
"rows": [
[
{ "p": "[b]Service[/b]" },
{ "p": "[b]Hours[/b]" },
{ "p": "[b]Rate[/b]" },
{ "p": "[b]Total[/b]" }
]
]
}
},
{ "p": "Grand Total: $data.invoice.grandTotal", "style": "total" },
{ "p": "Payment Terms:" },
{
"ol": {
"source": "$data.paymentTerms"
}
},
{ "p": "Thank you for your business, $data.client.contactName." }
]
}
}
Data
{
"document": {
"title": "Professional Services Invoice",
"date": "March 29, 2026"
},
"client": {
"companyName": "Meridian Logistics",
"contactName": "Sarah Mitchell"
},
"lineItems": [
{ "service": "Platform setup", "hours": "80", "rate": "$150", "total": "$12,000" },
{ "service": "API integration", "hours": "40", "rate": "$175", "total": "$7,000" },
{ "service": "User training", "hours": "16", "rate": "$125", "total": "$2,000" }
],
"invoice": {
"grandTotal": "$21,000"
},
"paymentTerms": [
"Wire transfer to ShipForge Ltd account",
"Reference: INV-SF-2026-0329",
"Net 30 days from invoice date"
]
}
Result
The generated document (PDF or DOCX) contains:
- A heading "Professional Services Invoice" with the subtitle "Prepared for Meridian Logistics on March 29, 2026"
- A table with a header row and three data rows for the line items
- The grand total "Grand Total: $21,000"
- A numbered list of payment terms
- A closing line "Thank you for your business, Sarah Mitchell."
Key points
sourceandmapare placed inside thetableorul/olobject, beside itsrowsorli.- The header row in a table is preserved; data rows are appended after it.
- For lists,
limay be omitted when usingsource-- items are generated from the data array. Literalliitems are kept once; anliwith$itemtokens is the template repeated for each element. - A table row or list item with
$itemtokens is the alternative tomap; the two are never combined in one container. - Binding happens before layout, so the PDF and the DOCX draw the same rows.
sourcevalues are$datapaths, just like scalar references.- You can combine scalar
$datareferences andsourcein the same document.