Skip to content

Bindings and conditions

Every read and write names state with a JSON Pointer. Mica accepts a pointer when:

  • it starts with / and names at least one key (/ alone is refused);
  • it is at most 512 characters;
  • no segment is empty, contains ~, begins or ends with a space, is -, is $state, or is one of __proto__, prototype, constructor;
  • it is not /mica or under it — that namespace belongs to the host.

The same rules apply to the keys of ui.state, which may also not contain /.

Once a document declares business objects, the paths each alias owns are read-only for the document (see business objects), and a read inside /objects/{alias} or /meta/objects/{alias} must name something the runtime actually projects.

json-render resolves these before a component sees its props. Mica accepts an expression only where the component’s schema opts in; anywhere else a $-key is refused.

{ "$state": "/guest/name" }

Accepted by Text.content, Heading.content and Value.value in both packs, by Value.error, and by the writable and error of Signal’s form controls (error takes only this read; see forms). The value is read live on every render.

$label — show a Choice’s chosen option

Section titled “$label — show a Choice’s chosen option”
{ "$label": "track" }

Accepted by Signal’s Text.content and Value.value only. It names a Choice element by its key, and that Choice’s value must be bound with $bindState. It shows the label of the chosen option, or for checkboxes the chosen labels in option order, comma-separated; nothing while none is chosen; and a stored value no option has as it is. It is for display: no condition, $cond, binding or action param takes it. Deleting the Choice is refused while any $label read of it remains. See show answers and values.

{ "$item": "reference" }
{ "$index": true }

Only inside the template of a repeated Stack or Grid (see lists). $item reads a field of the current row — a nested field /-joined, with no leading /, like address/city — in Text.content, Heading.content, Value.value and as a condition part’s $item in visible; over a collection the field must be declared. $index is the row’s zero-based position, in Text.content, Heading.content and Value.value only. An action in the template reads $item nested in a value slot (see actions); no action reads $index.

$format — show a value as money, a date or a count

Section titled “$format — show a value as money, a date or a count”
{ "$format": "currency", "value": { "$state": "/objects/claim/data/amount" }, "currency": "EUR" }

Accepted wherever $state is accepted in Text.content, Heading.content and Value.value, in both packs. It shows one value as display text, in the host’s locale, so a host returns the raw value (1250, "2026-10-11") rather than a display field such as amountLabel. value is a $state read, inside a template an $item read, or a $calc. Import refuses a literal value: fixed text needs no formatting, so write it as the content itself.

$format Options value Shows (in en-GB)
"number" — a number 1,250.5
"currency" currency: an ISO 4217 code in capitals, required a number €1,250.00
"percent" — a fraction: 0.25 is 25% 25%, 4.25% (up to two decimals)
"date" — a date as text, YYYY-MM-DD 11 Oct 2026
"count" one and other: the wording for exactly one and for any other count, both required a number, or a list (its rows are counted) 1 claim, 3 claims
  • The locale is the host’s choice: micaDirectives formats in the browser’s locale and createMicaDirectives({ locale }) in the host’s (see the runtime API). The designer formats in the browser’s.
  • A date shows the calendar day it names, whatever the viewer’s time zone.
  • A count shows one when the number is exactly 1 and other for every other number (0, 1.5, 2…), in every locale: the wording is in the document’s language, so only the number follows the locale. For a language that needs more plural forms, have the host supply the text.
  • A value that is missing or not of the format’s kind shows nothing. Import judges a read’s path, never the value it holds, so a read of text under "currency" is accepted and renders empty.
  • $format is display only. Import refuses it in action params and in conditions, which take the raw value, and refuses a $format inside value, and "date" around a $calc, which gives a number.
  • No templates: “3 of 4” or a full name is still the host’s to compute (see the host boundary).
{ "$calc": "product", "args": [{ "$state": "/order/price" }, { "$state": "/order/quantity" }] }
{ "$calc": "sum", "list": { "$state": "/basket" }, "field": "price" }

Accepted wherever $format is — Text.content, Heading.content and Value.value, in both packs — and as a $format’s value, to show the result as money or a count:

{ "$format": "currency", "value": { "$calc": "product", "args": [{ "$state": "/order/price" }, { "$state": "/order/quantity" }] }, "currency": "EUR" }

It computes a number from the document’s live state, so a form shows its total while the person types, without a host round trip. It is display only: the result is never sent to the host and no condition reads it. The host recomputes anything that counts from the raw inputs, as it re-validates them, and owns every decision (eligibility, pass or fail, approval).

$calc Operands (args) Gives
"sum" 2 to 16 a + b + …
"product" 2 to 16 a × b × …
"difference" exactly 2 a − b
"quotient" exactly 2 a ÷ b
"round" exactly 1, and places: 0 to 6, default 0 a rounded half away from zero
"min", "max" 2 to 16 the smallest or largest
"daysBetween" exactly 2 reads of YYYY-MM-DD dates whole days from the first to the second (negative when the second is earlier)
  • An operand is a number, a $state read, inside a template an $item read (held to the same rules as anywhere else), or another $calc. Calculations nest at most 3 deep, counting the outermost. daysBetween takes reads only.
  • sum, min and max may instead take one field of every row of a list: list is a $state read of the list and field the row field, named as an $item would name it (declared, over a collection). Over an empty list sum is 0, and min and max show nothing.
  • A read that is missing or not a finite number (text, an emptied number Input), a list row without one, a date that is not a real YYYY-MM-DD day, a division by zero or a result too large shows nothing, never NaN or an error. Import judges a read’s path, never the value it holds.
  • Results drop floating-point noise (0.1 + 0.2 shows 0.3). Unformatted, a result shows as the bare number; wrap it in $format for the viewer’s locale.
  • Import refuses an unknown function (there is no average), the wrong number of operands, a key a function does not take, nesting deeper than 3, a $format operand, and $calc anywhere but these props: in action params and object inputs, visible, $cond, requiredWhen and every other condition, and every other prop.
  • micaDirectives evaluates it; a host that registers Mica’s directives needs no change (see the runtime API).

$expr — typed formula for display or a condition

Section titled “$expr — typed formula for display or a condition”
{ "$expr": "or", "args": [
{ "$expr": "isEmpty", "args": [{ "$state": "/form/name" }] },
{ "$expr": "isEmpty", "args": [{ "$state": "/form/email" }] }
]}

The arithmetic $calc already has, plus comparison (eq, neq, gt, gte, lt, lte), boolean (and, or, not), emptiness (isEmpty) and branch (if). A number or text $expr may sit in the display props $calc takes (Text.content, Heading.content, Value.value; arithmetic, or if choosing between values; comparisons only inside if’s condition); only a number $expr may be a $format’s value. A boolean $expr is refused in a display slot. A boolean $expr may be the whole visible, $cond (required, disabled, busy) or requiredWhen. Import refuses it in setState, object inputs and host-action params. JSON AST only: no text syntax, no JS, no now(), concat or host-declared functions. Nesting 6, 32 nodes. Mica evaluates boolean $expr itself; json-render’s evaluateVisibility is not the boolean path. A $state read inside and, or, not or if’s condition counts as true only when it is exactly true, unlike a $state condition part; test text or lists with isEmpty, numbers with gt or eq.

$calc stays legal and display-only.

{ "$bindState": "/drafts/customer/displayName" }

Accepted by the value of Signal’s form controls only — Input, NumberField, Choice, Toggle, DateField and Slider, and a DateRange’s start and end — and $state is refused there. What each writes:

Control Writes
Input text, with its line breaks in a text area; a number when inputType is "number" and the text is one
NumberField the raw number (a percent as a fraction); null once cleared
Choice, display "radio", "select", "segmented" or "combobox" the chosen option’s value, text or a number
Choice, display "checkboxes" a list of the ticked options’ values, in option order; [] when none
Toggle true or false
DateField; DateRange start, end an ISO date, "YYYY-MM-DD"; "" once cleared
Slider a number between its min and max

A control shows a value it cannot edit read-only and never overwrites it: an Input over a record or a list, a NumberField over anything but a number, a Choice over anything it could not have written, a Toggle over anything but true or false, a date control over anything but an ISO date or "", a Slider over anything but a number. See forms.

A $bindState target must:

  • pass the state path rules and be writable (not /mica, not owned by a declared object);
  • contain no numeric segment (/tags/0);
  • not be a repeated list, inside one, or a container of one — a row’s field is edited with $bindItem;
  • not be a container of any other path the document references — reads, conditions, object inputs, setState targets and values, startup inputs, requiredWhen conditions or other bindings.

$bindItem — edit a field of the current row

Section titled “$bindItem — edit a field of the current row”
{ "$bindItem": "title" }

Accepted by the value of Signal’s form controls only (a DateRange’s start and end), inside the template of a repeated Stack or Grid over a local list; each row’s control edits its own row — a Toggle can tick a row off. The field must:

  • name a field, /-joined when nested, never the whole row ("") or a position (tags/0);
  • not be the key of any repeat over the list;
  • not be a container of any other read of the same list’s rows — from any template and in any form, including a positional $state read such as /todos/0/address/city.

A collection’s rows belong to the host and are never a $bindItem target; copy the row into a draft and save it with update. A field holding a record or a list is shown read-only.

{ "$cond": { "$state": "/drafts/decision", "eq": "rejected" }, "$then": true, "$else": false }

Accepted by the required of Signal’s form controls, and by every pack’s Button disabled and busy, always with exactly $then: true and $else: false. The condition uses the grammar below. A Button that is disabled or busy ignores presses; while busy it shows its busyLabel, when it has one, in place of its label:

{
"label": "Sign up",
"busy": { "$cond": { "$state": "/meta/objects/signup/operations/create/phase", "eq": "loading" }, "$then": true, "$else": false },
"busyLabel": "Sending…"
}

One grammar serves an element’s visible, a $cond prop, and an operation input’s requiredWhen. A condition is one part or a non-empty list of parts that must all hold. A part is an object with a $state path, at most one comparison, and optionally "not": true:

Part Holds when
{ "$state": p } the value at p is truthy — any list is, even an empty one
{ "$state": p, "eq": v } the value is strictly equal to v
{ "$state": p, "neq": v } the value is not strictly equal to v
{ "$state": p, "gt": n } (gte, lt, lte) the value and n are both numbers and the comparison holds
  • eq/neq compare against text (up to 10,000 characters), a number, true/false, null, or { "$state": q }.
  • gt, gte, lt and lte compare against a number or { "$state": q }.

"not": true inverts the part it sits on — that part only, never the whole list:

Part Holds when
{ "$state": p, "not": true } the value at p is falsy or missing
{ "$state": p, "eq": v, "not": true } the value is not strictly equal to v (the same as neq)
{ "$state": p, "neq": v, "not": true } the value is strictly equal to v (the same as eq)
{ "$state": p, "gt": n, "not": true } (gte, lt, lte) the comparison fails — including when either side is not a number

The same applies to a $item part in a template. not may only be true; "not": false or any other value is refused:

visible: not may only be true (it inverts the condition); remove it to keep the condition as is.

Because a missing value is falsy, { "$state": "/todos/0", "not": true } holds when the list at /todos has no first row — how a local list says it is empty.

{ "$or": [group, …] } holds when any group does. Each group is one part or a non-empty list of parts that must all hold, and an $or holds 1 to 8 groups. It is the whole condition: one level only, never inside a group or a list, and nothing sits beside it. One Next for talks, or for the workshop once dietary needs are filled:

"visible": { "$or": [
{ "$state": "/form/track", "eq": "talks" },
[{ "$state": "/form/track", "eq": "workshop" }, { "$state": "/form/dietary" }]
] }

To show a hint while any required field is empty, give each field a group: { "$or": [{ "$state": "/form/name", "not": true }, { "$state": "/form/email", "not": true }] }.

Refused, each with its own message: a bare true/false, $and, an $or inside a group or a list, an $or with no group or more than 8, an $or with any key beside it (not included), an empty group, $computed, $item/$index, not with any value but true, or more than one comparison in a part.