Data binding and expressions

How DocStudio binds JSON to templates: path bindings, fallbacks, the missing-data policies, the 35 expression functions, formatters and conditional styling.

Three kinds of expression

An expression is a JSON value. It is one of:

"Plain text"
{ "path": "customer.name" }
{ "path": "customer.nickname", "fallback": { "path": "customer.name" } }
{ "fn": "mul", "args": [{ "path": "qty" }, { "path": "price" }] }

A literal, a path with an optional fallback, or a function call. There is no textual expression language and nothing is evaluated as JavaScript.

Functions

The function set is closed. Functions are total: wrong types, division by zero or an unknown formatter give an empty value and a diagnostic, never an exception.

Group Functions
Arithmetic add, sub, mul, div, mod, round, abs, number
Comparison eq, ne, gt, gte, lt, lte
Logic and, or, not, if, coalesce
Presence exists, isEmpty, contains, in
Text concat, upper, lower, trim, length, substr
Aggregates sum, avg, count, min, max
Formatting format

Numbers are never converted from text automatically, so use number for decimal text. if evaluates only the branch it needs. An aggregate takes a list and an optional per-item expression in of:

{
  "fn": "sum",
  "args": [{ "path": "items" }],
  "of": { "fn": "mul", "args": [{ "path": "qty" }, { "path": "price" }] }
}

Inside a table footer, use { "path": "$rows" } as the list. Outside a table or repeater, $rows is a scope error.

Formatters

format takes a formatter name, a value and options. Built in: date (short, medium, long, full, iso, optional time zone), number (decimals), currency (a three-letter code, decimals), percent (decimals) and boolean (texts for true and false). Register your own with registerFormatter.

{ "fn": "format", "args": ["currency", { "path": "total" }, "USD"] }

Missing data

config.missingData controls what happens when a path finds nothing:

Policy Shows Diagnostic
blank Nothing None
placeholder (default) A dash None
warn Nothing MISSING_DATA warning
error Nothing MISSING_DATA error

null counts as missing. An empty string is shown as empty text. 0 and false are real values. A fallback replaces only a missing value. Use placeholder while designing and warn or error for production output.

Conditions and styles

when on a node is an expression. When it is false the node is not drawn. styleWhen is a list of { when, style } rules that apply on top of the normal style. Truthiness: false, 0, empty text, null, a missing value and an empty list are false.

Limits

An expression call takes at most 64 arguments, and depth, node count and total work are bounded. See the feature page for a worked example.

Last updated 2026-12-03