$keys
$keys(value?) -> arrayCompact type signature
<x-:a<s>>If value is omitted, the current context value is used.
Source: JSONata
Documentation
Returns an array containing the keys in the object. If the argument is an array of objects, then the array returned contains a de-duplicated list of all the keys in all of the objects.
Examples
List keys on an object
Input
This example uses the patient-summary example input. The expression selects the nested identifiers object and lists its keys.
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
$keys(identifiers)
Result
["memberId", "recordNumber"]