jq -R : Read Raw Lines as Strings
The jq -R flag treats each input line as a raw string rather than parsing it as JSON.
Turning plain command output, like a list of branch names, into a JSON array is the job of -R, often with -s, in a CI step.
What it does
-R (--raw-input) makes jq read each line of input as a JSON string instead of expecting JSON. Combined with -s (slurp) it reads the whole input as one string, which split("\n") turns into an array of lines. This bridges plain text into JSON processing.
Common usage
# wrap each line as a JSON string
printf 'main\ndev\n' | jq -R '.'
# build a JSON array from lines
git branch --format='%(refname:short)' | jq -R -s 'split("\n") | map(select(length > 0))'
# parse a key=value file into an object
jq -R -s 'split("\n") | map(select(length>0) | split("=") | {(.[0]): .[1]}) | add' .envFlags
| Flag | What it does |
|---|---|
| -R, --raw-input | Each line becomes a JSON string |
| -R -s | Whole input as one string to split |
| split("\n") | Turn the slurped text into lines |
| -r | The output-side raw equivalent |
In CI
Use -R to lift plain command output into JSON so jq can filter and reshape it. The common -R -s | split("\n") idiom converts a newline list into an array; drop the trailing empty element with select(length > 0).
Common errors in CI
Forgetting -R on plain text gives "jq: error (at <stdin>:0): ... Invalid numeric literal" or "syntax error" because jq tried to parse text as JSON. Under -R -s, an extra empty string in the array comes from the trailing newline; filter it with select(length > 0).