Skip to main content

Data Binding Overview

Data Binding lets you build reusable document templates with placeholder references that are resolved at generation time. Instead of hardcoding values into your document definition, you use $data references that get replaced with actual data when the PDF or DOCX is generated.

How it works​

  1. Author a template with $data.path.to.value references in your document definition.
  2. Provide a data object alongside the template when generating a PDF or DOCX.
  3. DocPayload resolves all $data references, replacing them with values from your data object.
  4. The PDF or DOCX is rendered with the resolved content.

Scalar references​

The most basic form of Data Binding is a scalar reference -- a $data path that points to a single value in your data object.

Template​

{
"document": {
"styles": {
"title": { "fontSize": 18, "fontWeight": "bold" },
"highlight": { "color": "#E94560", "fontWeight": "bold" }
},
"content": [
{ "p": "Invoice for $data.client.companyName", "style": "title" },
{ "p": "Invoice Number: $data.invoice.number" },
{ "p": "Prepared by: $data.user.name" },
{ "p": "Contact: $data.user.email" },
{ "p": "Amount Due: [b]$data.invoice.totalAmount[/b]", "style": "highlight" }
]
}
}

Data​

{
"client": {
"companyName": "GlobalTech Industries"
},
"user": {
"name": "Laura Bennett",
"email": "laura.bennett@shipforge.io"
},
"invoice": {
"number": "INV-2026-0317",
"totalAmount": "$24,500"
}
}

Result​

The resolved paragraphs become:

  • "Invoice for GlobalTech Industries"
  • "Invoice Number: INV-2026-0317"
  • "Prepared by: Laura Bennett"
  • "Contact: laura.bennett@shipforge.io"
  • "Amount Due: $24,500"

Path syntax​

References use dot-separated paths to traverse nested objects in your data.

ReferenceData path
$data.nameTop-level name property
$data.client.companyNamecompanyName inside client object
$data.client.address.citycity inside address inside client

What a path may contain​

A path is made of ASCII letters, digits, _ and ., and it ends at the first other character. A key spelled with a hyphen, a space or an accented letter cannot be reached: $data.my-key reads $data.my, and -key is text. Name such keys in camelCase or snake_case in your data. A . at the end of a path is sentence punctuation, not a segment: Total: $data.total. ends with a full stop.

Array indexing​

A segment of digits indexes an array, counting from 0. Bracket notation is not read: $data.items[0].name would collide with the closing tag of an inline format such as [/b], so it is drawn as written and reported.

ReferenceDescription
$data.items.0.nameFirst element's name property
$data.company.bills.3.amountFourth bill's amount inside company
$data.matrix.0.1Chained indexes — row 0, column 1
$item.addresses.0.cityArray indexing inside $item context
{ "p": "Primary contact: $data.contacts.0.name — $data.contacts.0.email" }

With data:

{
"contacts": [
{ "name": "Alice Chen", "email": "alice@acme.com" },
{ "name": "Bob Park", "email": "bob@acme.com" }
]
}

This renders: "Primary contact: Alice Chen — alice@acme.com"

Array indexing works everywhere $data references work, including inside $item paths when iterating table/list data. If the index is out of bounds or the value is not an array, the reference is drawn as written and the render reports it.

What a value places​

Value in the dataWhat is drawn
a stringthe string
a number or a booleanthe value as the JSON writes it: 42, true
nullnothing
an object or an arraynothing is placed: the token is left standing and the report says the path names an object or an array. Name a value inside it, or repeat a row per element with source

A string that itself holds a $data token is resolved in its turn before it is placed, through up to four levels, so a sentence kept once in the data can carry a reference of its own:

{
"issuer": { "domain": "acme.example" },
"legal": "Terms on $data.issuer.domain/terms."
}

{ "p": "See: $data.legal" } draws "See: Terms on acme.example/terms.". A chain longer than four, or a value that names itself, stops there, and the token left standing is reported.

A string is also read as the template's own text is, so a shortcode in it is a shortcode:

{ "finding": "[b]Urgent:[/b] replace the door seal" }

{ "p": "$data.finding" } draws "Urgent:" in bold. A value can open a link, place a form field or an image, or close a tag the template left open, the same way.

This holds for every value, including one typed by someone outside your organisation: a name, an address, a comment. To draw such a value exactly as it was typed, double each [ before you send it: [[ is drawn as one bracket and opens no tag. A $data token has no such escape, so take it out of a value that must not reach the rest of the data.

Where references work​

A $data token resolves in every string an author writes as text or as a value, before the document is laid out, so the PDF and the DOCX are drawn from the same resolved definition:

WhereWhat resolves
Content nodesthe text of p, h1-h6, th, td, title, list items and columns; a table's, an image's or an svg's caption; an image's src and alt
Inline shortcodesthe tokens inside them: [b]$data.invoice.total[/b], a field's default [textfield, name, '$data.applicant.name']
A node's stylethe style name itself: "style": "$item.severity" lets the data choose a row's style
Header, footer, watermarks, section bandseverything above, as in the body
svgtext and textPath text, an image href, a barcode's payload
Form fieldsa field's name, label, value and options
metadatatitle, author, subject, keywords (not name or version, which are identifiers)
outlineseach entry's title
signature.appearancesignedBy, signDate, reason, location
encryptionuserPassword, ownerPassword. A user password bound to a value that comes out empty is refused, so a missing value never leaves a document open to anyone

Unresolved references​

If a $data reference points to a path that does not exist in the provided data object, the reference text is preserved as-is in the output, and the render report names it. This means $data.missing.key will appear literally as "$data.missing.key" in the PDF or DOCX.

{ "p": "Unresolved ref stays: $data.missing.key" }

This behavior ensures that missing data does not cause generation failures, while making missing values easy to spot both in the output and in the report.

Default values: params​

A document may declare params: a default for each $data key it reads. The bound data wins, key by key at the top of the data, so a definition renders on its own with its defaults (a preview, a gallery card) and with real values once data is bound:

{
"document": {
"params": { "currency": "EUR", "client": { "name": "Sample client" } },
"content": [
{ "p": "Prepared for $data.client.name, amounts in $data.currency" }
]
}
}

Rendered alone, the paragraph reads "Prepared for Sample client, amounts in EUR". Bound with { "client": { "name": "Meridian" } }, it reads "Prepared for Meridian, amounts in EUR": the data's client replaces the default client whole, and currency keeps its default. On a component, params plays the same part against the params of a use site; see Components.

References inside inline formatting​

$data references work inside any inline formatting tag. The reference is resolved first, then the formatting is applied.

{ "p": "[b]Client:[/b] $data.client.companyName - [color, #CC0000]$data.client.address.city[/color]" }

With data { "client": { "companyName": "Meridian Logistics", "address": { "city": "Denver" } } }, this renders as:

Client: Meridian Logistics - Denver (in red)

Beyond scalar references​

DocPayload supports two additional Data Binding mechanisms for populating collections:

  • Data Source -- Populate table rows from arrays of objects and list items from string arrays.
  • Templates -- Store document definitions as reusable templates and generate PDFs or DOCX files by passing data at request time.
  • Globals -- Built-in $global.* tokens for date, time, page numbers, and document metadata, no data object required.

Quick comparison​

FeatureSyntaxUse case
Scalar ref$data.path.to.valueReplace individual values in text
Array index$data.items.0.nameAccess a specific array element by position
Table source"source": "$data.items"Generate table rows from an array
List source"source": "$data.notes"Generate list items from an array
Global token$global.NAMEBuilt-in values: date, page numbers, metadata