Dynamic data binding

Bind JSON to text, tables and repeaters with paths, fallbacks and a declarative expression language that never runs JavaScript.

The designer Data tab showing the sample JSON that is merged into the template
The designer Data tab showing the sample JSON that is merged into the template

Data binding connects a template to your JSON. The data can have any shape, and no schema is required.

A worked example

The template:

template.json
{
  "schemaVersion": "1.0.0",
  "config": { "missingData": "placeholder" },
  "body": [
    {
      "id": "greeting",
      "type": "text",
      "content": [
        "Hello ",
        { "path": "customer.nickname", "fallback": { "path": "customer.name" } },
        ", your balance is ",
        { "fn": "format", "args": ["currency", { "path": "balance" }, "USD"] }
      ]
    },
    {
      "id": "late",
      "type": "text",
      "content": ["Payment overdue"],
      "when": { "fn": "gt", "args": [{ "path": "daysOverdue" }, 30] },
      "style": { "color": "#b42318" }
    }
  ]
}

The data:

data.json
{ "customer": { "name": "Ada" }, "balance": 1234.5, "daysOverdue": 45 }

The first line renders as Hello Ada, your balance is $1,234.50, because nickname is missing and the fallback applies. The second line appears only because daysOverdue is greater than 30.

Binding syntax

Form Example
Literal "Hello", 42, true, null
Path { "path": "customer.name" }
Path with fallback { "path": "nickname", "fallback": "Guest" }
Function call { "fn": "add", "args": [1, { "path": "n" }] }
Aggregate { "fn": "sum", "args": [{ "path": "items" }], "of": { "path": "amount" } }

Special names such as $index, $count, $parent, $root, $rows and $props are available in repeaters, tables and components.

35 built-in functions

Arithmetic, comparison, logic, presence, text, aggregates and formatting. The set is closed: a template cannot define new functions, and a function with wrong input returns an empty value and a diagnostic instead of throwing. Built-in formatters: date, number, currency, percent and boolean. Register your own with registerFormatter.

Safe by design

There is no textual expression language and nothing is evaluated as JavaScript. Paths reject __proto__, constructor and prototype. Depth, node count, array length and total work are bounded.

Missing data

Four policies decide what a missing value does: blank, placeholder, warn and error. Use placeholder while designing and warn or error in production.

Limits

A call has at most 64 arguments. Numbers are not converted from text automatically, so use number for decimal text. Learn more in the data binding concepts.

Related documentation