Skip to main content

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​

PropertyTypeDescription
sourcestring$data path pointing to an array of objects
mapstring[]Array of object keys, mapped to columns left-to-right

How it works​

  1. Define the table with its widths and a header row in rows.
  2. Set source to a $data path pointing to an array of objects.
  3. Set map to specify which object keys map to which columns.
  4. 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:

DescriptionQtyAmount
Cloud migration120$18,000
Security audit40$6,000
Training sessions16$2,400

Column mapping​

The map array maps object keys to columns positionally:

  • map[0] maps to the first column
  • map[1] maps to the second column
  • map[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 }]
]
}
}
TokenWhat it reads
$item.namea property of the element; digit segments index arrays, as in $data paths ($item.lines.0.sku)
$itemthe 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.NUMBERthe element's position, counting from 1
$item.COUNTthe 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 toTemplate rows or itemsmap, or no template
an array with elementsone copy per elementone row or item per element
an empty arrayliteral rows are drawn once, template rows zero times, $item.COUNT is 0; nothing is reportednothing is added, and the report says the source has no items
nothing, or not an arraythe rows and items stay as written, so the report names each $item token left standing, and says the source has no itemsnothing 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​

PropertyTypeDescription
sourcestring$data path pointing to an array
mapstringOptional template for each item (e.g. "$item.name — $item.role")

How it works​

  1. Define the list (ul or ol) with source inside it.
  2. Set source to a $data path pointing to an array.
  3. 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:

  1. A heading "Professional Services Invoice" with the subtitle "Prepared for Meridian Logistics on March 29, 2026"
  2. A table with a header row and three data rows for the line items
  3. The grand total "Grand Total: $21,000"
  4. A numbered list of payment terms
  5. A closing line "Thank you for your business, Sarah Mitchell."

Key points​

  • source and map are placed inside the table or ul/ol object, beside its rows or li.
  • The header row in a table is preserved; data rows are appended after it.
  • For lists, li may be omitted when using source -- items are generated from the data array. Literal li items are kept once; an li with $item tokens is the template repeated for each element.
  • A table row or list item with $item tokens is the alternative to map; the two are never combined in one container.
  • Binding happens before layout, so the PDF and the DOCX draw the same rows.
  • source values are $data paths, just like scalar references.
  • You can combine scalar $data references and source in the same document.