$distinct
$distinct(array) -> arrayCompact type signature
<x:x>Source: JSONata
Documentation
Returns an array containing all the values from the array parameter, but with any duplicates removed. Values are tested for deep equality as if by using the equality operator.
Examples
Deduplicate codes
Input
This example uses the diagnoses example input. The expression projects every code value and removes duplicates.
Example input
JSON
[
{
"code": "DX-001",
"display": "tension-type headache",
"recordedAt": "2026-02-14T09:55:00Z",
"clinicalStatus": "active",
"rank": 1
},
{
"code": "DX-014",
"display": "seasonal allergic rhinitis",
"recordedAt": "2026-02-14T10:00:00Z",
"clinicalStatus": "active",
"rank": 2
},
{
"code": "DX-032",
"display": "elevated blood pressure reading",
"recordedAt": "2026-03-01T15:35:00Z",
"clinicalStatus": "active",
"rank": 1
},
{
"code": "DX-077",
"display": "resolved acute sinusitis",
"recordedAt": "2026-01-05T13:20:00Z",
"clinicalStatus": "resolved",
"rank": 3
}
]
Expression
$distinct(code)
Result
["DX-001", "DX-014", "DX-032", "DX-077"]