Tools
Get Pro

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 it

Input

[
  {
    "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.json

Compute a new value

The filter inside map can be any expression — math, strings or objects.

.items | map(.qty * .price)CompactTry it

Input

{
  "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 it

Input

{
  "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.5
add sums the array: the order total. jq '.items | map(.qty * .price) | add' data.json

Reshape every item

Build a new object per item. See building objects for more.

map({name, senior: (.age >= 40)})CompactTry it

Input

[
  {
    "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.json

map and select together

map(select(...)) filters an array and keeps it an array.

map(select(.age < 30) | .name)CompactTry it

Input

[
  {
    "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.json

Transform object values: map_values()

map_values(f) keeps the keys of an object and replaces each value.

.env | map_values(ascii_upcase)Try it

Input

{
  "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 it

Input

{
  "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"
}
Turn numeric strings into numbers, leave the rest. jq '.env | map_values(tonumber? // .)' data.json

Common mistakes

  • map needs an array. On an object, use map_values or to_entries | map(...).
  • If the inner filter outputs nothing for an item (for example empty or a failing select), 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.