distinctBy
Remove duplicate values from an array using a key extractor to determine uniqueness. Keeps the first element for each key.
array(required): the array to deduplicatekeyFn(required): lambda(element) -> key
bash
echo '{"orders": [{"id": 1, "cust": "C-42"}, {"id": 2, "cust": "C-42"}, {"id": 3, "cust": "C-41"}]}' \
| utlx -e 'distinctBy($input.orders, (o) -> o.cust)'
# [{"id": 1, "cust": "C-42"}, {"id": 3, "cust": "C-41"}]utlx
{
onePerCustomer: distinctBy($input.orders, (o) -> o.customerId)
}
// keeps first order per customer, removes duplicates