Skip to main content

$zip

$zip(...arrays) -> array
Compact type signature<a+>
Browse categories

Source: JSONata

Documentation

Combines the items at matching positions from two or more arrays into tuple arrays.

$zip() stops at the shortest input array. If any argument is not an array, it contributes a length of 0, so the zipped result is empty.

Examples

Zip two arrays by position

Input

This example uses the patient-summary example input. The expression pairs each patient tag with a label from a second array.

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

$zip(tags, ["primary", "secondary"])

Result

[
[
"demo",
"primary"
],
[
"fictional",
"secondary"
]
]