jq map() and map_values()
map(f) runs a filter on every item of an array and returns the new array. It is shorthand for [.[] | f].
Pull one field from every item
map(.name)CompactTry itInput
[
{
"name": "Ada",
"age": 36,
"team": "core"
},
{
"name": "Linus",
"age": 28,
"team": "kernel"
},
{
"name": "Grace",
"age": 45,
"team": "core"
},
{
"name": "Ken",
"age": 28,
"team": "kernel"
}
]Output
["Ada","Linus","Grace","Ken"]jq -c 'map(.name)' data.jsonCompute a new value
The filter inside map can be any expression — math, strings or objects.
.items | map(.qty * .price)CompactTry itInput
{
"id": "A-1001",
"customer": {
"name": "Ada Lovelace",
"address": {
"city": "London",
"zip": "NW1"
}
},
"items": [
{
"sku": "pen",
"qty": 3,
"price": 1.5
},
{
"sku": "notebook",
"qty": 1,
"price": 4
}
],
"status": "paid",
"created at": "2026-11-01T10:00:00Z"
}Output
[4.5,4]jq -c '.items | map(.qty * .price)' data.json.items | map(.qty * .price) | addTry itInput
{
"id": "A-1001",
"customer": {
"name": "Ada Lovelace",
"address": {
"city": "London",
"zip": "NW1"
}
},
"items": [
{
"sku": "pen",
"qty": 3,
"price": 1.5
},
{
"sku": "notebook",
"qty": 1,
"price": 4
}
],
"status": "paid",
"created at": "2026-11-01T10:00:00Z"
}Output
8.5add sums the array: the order total. jq '.items | map(.qty * .price) | add' data.jsonReshape every item
Build a new object per item. See building objects for more.
map({name, senior: (.age >= 40)})CompactTry itInput
[
{
"name": "Ada",
"age": 36,
"team": "core"
},
{
"name": "Linus",
"age": 28,
"team": "kernel"
},
{
"name": "Grace",
"age": 45,
"team": "core"
},
{
"name": "Ken",
"age": 28,
"team": "kernel"
}
]Output
[{"name":"Ada","senior":false},{"name":"Linus","senior":false},{"name":"Grace","senior":true},{"name":"Ken","senior":false}]jq -c 'map({name, senior: (.age >= 40)})' data.jsonmap and select together
map(select(...)) filters an array and keeps it an array.
map(select(.age < 30) | .name)CompactTry itInput
[
{
"name": "Ada",
"age": 36,
"team": "core"
},
{
"name": "Linus",
"age": 28,
"team": "kernel"
},
{
"name": "Grace",
"age": 45,
"team": "core"
},
{
"name": "Ken",
"age": 28,
"team": "kernel"
}
]Output
["Linus","Ken"]jq -c 'map(select(.age < 30) | .name)' data.jsonTransform object values: map_values()
map_values(f) keeps the keys of an object and replaces each value.
.env | map_values(ascii_upcase)Try itInput
{
"name": "api",
"env": {
"PORT": "8080",
"DEBUG": "false",
"REGION": "eu-west-1"
},
"replicas": 2,
"database": {
"host": "db.internal",
"password": "secret",
"pool": {
"max": 10,
"password": "hunter2"
}
}
}Output
{
"PORT": "8080",
"DEBUG": "FALSE",
"REGION": "EU-WEST-1"
}jq '.env | map_values(ascii_upcase)' data.json.env | map_values(tonumber? // .)Try itInput
{
"name": "api",
"env": {
"PORT": "8080",
"DEBUG": "false",
"REGION": "eu-west-1"
},
"replicas": 2,
"database": {
"host": "db.internal",
"password": "secret",
"pool": {
"max": 10,
"password": "hunter2"
}
}
}Output
{
"PORT": 8080,
"DEBUG": "false",
"REGION": "eu-west-1"
}jq '.env | map_values(tonumber? // .)' data.jsonCommon mistakes
mapneeds an array. On an object, usemap_valuesorto_entries | map(...).- If the inner filter outputs nothing for an item (for example
emptyor a failingselect), that item disappears from the result.
Practice
Open the jq Playground with your own JSON — it runs the real jq 1.8 in your browser, so nothing is uploaded. The jq cheat sheet lists every filter from these lessons on one page.