map(f) runs f on every element of an array and collects the results back into an array. It’s
[.[] | f] with less typing.
Example input
[
{ "name": "Ada", "price": 10 },
{ "name": "Linus", "price": 20 }
]
Pull one field from each
jq 'map(.name)' data.json # ["Ada","Linus"]
Do math on each
jq 'map(.price * 1.1)' data.json # [11, 22]
Reshape each object
jq 'map({ product: .name, withTax: (.price * 1.2) })' data.json
Output:
[
{ "product": "Ada", "withTax": 12 },
{ "product": "Linus", "withTax": 24 }
]
Add or change a field on each
jq 'map(.price += 5)' data.json # bump every price by 5
jq 'map(. + { currency: "USD" })' data.json # add a field to each object
map over object values with map_values()
For an object (not an array), use map_values(f) to transform each value, keeping keys:
{ "a": 1, "b": 2 }
jq 'map_values(. * 10)' obj.json # {"a":10,"b":20}
map(f) = [.[] | f]. Use map for arrays and map_values for objects. Combine with
select to filter-and-keep in one go: map(select(.price > 15)).