Skip to content
KajayDocs
SurveysSDK neutral

Expressions and conditional logic

Make survey state react to answers with references, conditions, and functions.

Expressions connect authored JSON to live answers. Kajay parses each expression, tracks the references it reads, and reruns only affected rules after an answer changes.

Drive element state with conditions

Three properties cover the common conditional behaviors:

visibleIf
Show the page, panel, question, or choice while truthy.
enableIf
Allow interaction while truthy.
requiredIf
Require a question while truthy.
shipping-survey.jsonjson
{
  "pages": [{
    "name": "shipping",
    "elements": [
      {
        "type": "boolean",
        "name": "needsShipping",
        "title": "Ship a physical copy?"
      },
      {
        "type": "text",
        "name": "address",
        "title": "Shipping address",
        "visibleIf": "{needsShipping} == true",
        "requiredIf": "{needsShipping} == true"
      },
      {
        "type": "text",
        "name": "trackingNote",
        "title": "Tracking note",
        "enableIf": "{address} notempty"
      }
    ]
  }]
}

Reference answers by name

Wrap an answer path in braces: {rating}, {address.city}, or{rows[0].price}. A missing path resolves to undefined; absent values compare equal to null and are considered empty.

Operators and function names are case-insensitive. Canonical output normalizes alternatives such as= to ==, && to and, and <> to!=.

Try an expression

Edit either input. This uses the same public parser, function registry, value resolver, evaluator, and canonical printer that an adapter can use.

Result
42
Canonical form
{amount} + 1

Date functions use the fixed reference clock 2026-08-02 12:34:56 UTC so results are repeatable.

Handle malformed logic safely

Evaluation errors never throw out of the expression engine. Runtime logic exposes them through survey.logicDiagnostics.expressionErrors, including a stable code and source span.

Conditional properties choose a safe fallback: a broken visibleIf or enableIf leaves content visible and enabled, while a broken requiredIf does not block submission.

Beyond conditional properties

The same language powers calculated values, expression questions, value rules, triggers, conditional completion messages, choice visibility, matrix totals, and expression validators. Use the expression language reference when you need exact coercion, precedence, or function behavior.