$sift
$sift(object?, function?) -> objectCompact type signature
<o-f?:o>If object is omitted, the current context value is used.
Source: JSONata
Documentation
Filters an object by applying a predicate to each key-value pair and returning a new object with only the matching members.
The callback receives the value, key, and source object. Predicate results are interpreted with JSONata boolean rules. If nothing matches, $sift() returns undefined rather than an empty object.
Use $sift() for object members and $filter() for arrays or sequences.
Examples
Keep selected object members
Input
This example uses the patient-summary example input. The expression removes the organization entry from the nested primaryCareTeam object while keeping the other members unchanged.
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
$sift(primaryCareTeam, function($v, $k) { $k != "organization" })
Result
{
"facility": "ExampleCare Clinic",
"practitioner": {
"practitionerId": "prac-4001",
"display": "Jordan Kim"
}
}