jq -c : Compact Single-Line JSON Output
The jq -c flag prints each JSON result compactly on a single line instead of pretty-printed.
A GitHub Actions matrix or a $GITHUB_OUTPUT value must be one line, so -c is the flag that makes jq output usable there.
What it does
-c (--compact-output) removes the indentation and newlines jq adds by default, emitting each result as one line of JSON. It does not merge multiple results onto one line; each top-level output is still its own line.
Common usage
# build a one-line matrix value
echo "matrix=$(jq -c 'map({name})' tags.json)" >> "$GITHUB_OUTPUT"
# compact NDJSON, one object per line
jq -c '.[]' items.json
# compact for a fromJSON consumer
jq -c '{include: map({os: .os})}' targets.jsonFlags
| Flag | What it does |
|---|---|
| -c, --compact-output | One line per result, no indent |
| -r | Combine for raw single-line strings |
| --tab | Indent with tabs (the opposite intent) |
| --indent n | Set a custom indent width |
In CI
Anything assigned to $GITHUB_OUTPUT or consumed by fromJSON in a matrix must be a single line; -c guarantees that. Pretty-printed JSON written to an output file confuses the parser with embedded newlines.
Common errors in CI
The classic failure is "Unable to process file command output successfully" or a matrix parse error because pretty-printed JSON spanned multiple lines; add -c. If -c still yields several lines, your program emits multiple results; wrap them in [ ... ] to make one array.