Skip to main content

$eval

$eval(expression, context?) -> value
Compact type signature<sx?:x>

Source: JSONata

Documentation

Parses and evaluates the supplied expression string against the current context.

Pass a second argument to replace the inner focus for that evaluation while still inheriting the surrounding environment bindings and registered functions. If the expression argument is undefined, $eval() returns undefined.

Use $eval() sparingly. It is useful when the expression must be assembled dynamically, but direct expressions are usually easier to read, validate, and maintain. Parse errors from the inner expression surface as D3120, while runtime failures surface as D3121.

Examples

Evaluate an expression against a nested focus

Input

This example uses the patient-summary example input. The expression evaluates memberId against the nested identifiers object instead of the top-level document.

Example input

JSON
{
"patientId": "pat-0001",
"name": {
"given": "Avery",
"family": "Reed",
"display": "Avery Reed"
},
"birthDate": "1990-06-12",
"sex": "female",
"primaryCareTeam": {
"organization": "ExampleCare",
"facility": "ExampleCare Clinic",
"practitioner": {
"practitionerId": "prac-4001",
"display": "Jordan Kim"
}
},
"identifiers": {
"memberId": "mbr-3001",
"recordNumber": "rec-5001"
},
"tags": [
"demo",
"fictional"
],
"_xmlTagName": "patientSummary"
}

Expression

$eval("memberId", identifiers)

Result

"mbr-3001"