Skip to content
Latchkey

jq -r : Raw Output Without JSON Quotes

The jq -r flag prints string results raw, without the surrounding double quotes JSON would normally add.

Capturing a value into a shell variable almost always needs -r so the variable does not carry literal quote characters in CI.

What it does

-r (--raw-output) makes jq emit string results verbatim instead of as quoted JSON strings. Non-string outputs (numbers, objects, arrays) are still printed as JSON. It affects only top-level string outputs, not strings nested inside an object.

Common usage

Terminal
# capture a clean value into a shell variable
NAME=$(gh api repos/cli/cli --jq '.name')
SHA=$(jq -r '.commit.sha' build.json)
# raw lines to loop over
jq -r '.[].name' tags.json | while read -r t; do echo "$t"; done

Flags

FlagWhat it does
-r, --raw-outputPrint strings without quotes
-j, --join-outputLike -r but no trailing newline
--raw-output0NUL-separate raw outputs
-R, --raw-inputThe input side equivalent

In CI

Without -r a captured value becomes "v1.2.3" including the quotes, which breaks string comparisons and path building downstream. Use -j when you need the output with no trailing newline, for example before piping into base64.

Common errors in CI

-r is not an error source itself; the usual bug is a value that still has quotes because -r was on the outer jq but the string is nested inside an object jq still renders as JSON. Project the string to the top level, or it stays quoted.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →