jq -s : Slurp Inputs Into One Array
The jq -s flag reads the entire input stream into one big array before running the filter once.
Combining several JSON documents, like paginated API pages or a stream of NDJSON lines, into one array is exactly what slurp is for in CI.
What it does
-s (--slurp) collects all the JSON values from the input into a single array and runs the program once on that array, instead of once per input. It is how you aggregate, sort, or sum across multiple documents or NDJSON lines.
Common usage
# concatenate paginated arrays into one
jq -s 'add' page1.json page2.json
# turn NDJSON into a single array
gh api repos/cli/cli/issues --paginate | jq -s 'flatten'
# count across all inputs
jq -s 'length' *.jsonFlags
| Flag | What it does |
|---|---|
| -s, --slurp | Read all inputs into one array |
| add | Common follow-up to merge arrays |
| flatten | Flatten an array of arrays by one level |
| -n + inputs | Alternative way to consume the stream |
In CI
gh api --paginate emits one array per page; pipe to jq -s "add" or "flatten" to join them. Without -s, jq processes each page separately and you only see the last one in a command substitution.
Common errors in CI
A program that worked on one document but returns "Cannot index array with \"x\"" under -s is now seeing the wrapping array; index .[] first. Conversely, "Cannot iterate over null" without -s on multi-document input means jq ran per-document and a later one was empty.