Skip to main content

$exists

$exists(value) -> boolean
Compact type signature<x:b>
Browse categories

Source: JSONata

Documentation

Returns Boolean true if the arg expression evaluates to a value, or false if the expression does not match anything (e.g. a path to a non-existent field or an undefined value).

Examples

Check whether an optional field is present

Input

This example uses the patient-summary example input. The expression checks whether the referenced nested paths are present.

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

{
"hasMemberId": $exists(identifiers.memberId),
"hasPractitionerPhone": $exists(primaryCareTeam.practitioner.phone)
}

Result

{
"hasMemberId": true,
"hasPractitionerPhone": false
}