Basics

Loop Over a JSON Array with jq (.[])

2 min · updated June 14, 2026

.[] is the array/object iterator — it emits each element as a separate output, which you then pipe into other filters.

Example input

[
  { "name": "Ada",   "age": 36 },
  { "name": "Linus", "age": 54 }
]

Emit each element

jq '.[]' data.json

Pull one field from every element

jq '.[].name' data.json

Output (one value per line):

"Ada"
"Linus"

Re-collect results into an array

Wrap the whole expression in [ ... ]:

jq '[.[].name]' data.json     # ["Ada","Linus"]

Iterate an array that’s nested under a key

jq '.users[]' data.json

Iterate the values of an object

.[] works on objects too — it emits each value (not the keys):

{ "a": 1, "b": 2 }
jq '.[]' obj.json     # 1  then  2

.[] vs [.[]]: bare .[] produces a stream of separate outputs; map(...) and [.[] | ...] collect that stream back into a single array. If a later step complains it got multiple inputs, you probably want the array form.

← All recipes