Skip to main content

$assert

$assert(condition, message?) -> undefined
Compact type signature<bs?:x>

Source: JSONata

Documentation

Use $assert() when a required condition must hold before the mapping can continue. It returns undefined when the condition is true. If the condition is false, it immediately terminates evaluation by throwing an error with the supplied message.

This helper belongs to Diagnostics And Errors: it does not log or trace execution, it enforces a precondition.

Examples

Validate a precondition (passes through)

Input

This example uses the eligibility example input. The expression validates the top-level active field.

Example input

JSON
{
"memberId": "mbr-3001",
"patientId": "pat-0001",
"plan": {
"planCode": "PLAN-100",
"planName": "ExampleCare Standard"
},
"active": true,
"effective": {
"start": "2026-01-01",
"end": "2026-12-31"
},
"copay": {
"visit": 25,
"urgentCare": 50
},
"deductibleRemaining": 300
}

Expression

$assert(active, "Eligibility is not active")

Result

undefined

Validate a precondition (fails)

Input

false

Expression

$assert($, "Eligibility is not active")

Result

Error (code D3141): Eligibility is not active