map
Transform every element of an array. The most-used function in UTL-X. Returns a new array of the same length.
array(required): the array to transformfn(required): lambda(element) -> newValueor(element, index) -> newValue
bash
echo '[1, 2, 3]' | utlx -e 'map(., (x) -> x * 2)'
# [2, 4, 6]utlx
{
lines: map($input.items, (item) -> {
product: item.name,
priceWithTax: item.price * 1.21
}),
// With index (second parameter):
numbered: map($input.items, (item, index) -> {
lineNumber: index + 1,
product: item.name
})
}Anti-pattern: using map() to filter — map(arr, (x) -> if (x.active) x else null) produces nulls. Use filter() to remove, then map() to transform.