Skip to content
Latchkey

yq: Output Style, Quoting, and -r Raw Values

yq prints scalars raw by default and exposes style operators to control quoting and flow style in the output.

How a value is quoted matters when another tool reads it. Go yq prints bare scalars without -r, sets quoting with the style operator, and that -r difference is a frequent cross-yq trip-up.

What it does

mikefarah/yq prints a scalar value with no surrounding quotes by default, so yq '.name' f.yaml already gives a raw string. The style = "double"/"single"/"flow" operator forces a quoting or flow style on output. There is no -r flag in Go yq; -r is a kislyuk/yq (Python) option to strip JSON string quotes.

Common usage

Terminal
yq '.metadata.name' deploy.yaml          # raw, no quotes (no -r needed)
yq '.image style="double"' values.yaml   # force double quotes on output
yq -o=json -I=0 '.' deploy.yaml          # compact JSON for a single line

Style controls

Expression / flagWhat it does
(default)Go yq prints scalars raw, unquoted
.a style="double"Force double-quoted output for .a
.a style="single"Force single-quoted output
.a style="flow"Inline (flow) style for maps/arrays
-I=0 with -o=jsonCompact single-line JSON
-r (Python yq only)Strip quotes; NOT a Go yq flag

In CI

Because Go yq already emits raw scalars, capture values directly: V=$(yq '.version' f.yaml); echo "version=$V" >> "$GITHUB_OUTPUT". Do not copy a -r from a jq or Python-yq snippet; Go yq rejects it as an unknown flag.

Common errors in CI

"Error: unknown shorthand flag: 'r'" means a script wrote yq -r for raw output, which is Python yq / jq syntax; on Go yq drop the -r since scalars are already raw. Values arriving wrapped in quotes when you expected raw usually means you are on kislyuk/yq, which JSON-encodes by default; -r there or the Go binary here fixes it. Forcing flow style on a file meant to stay block-style produces an unexpectedly compact diff.

Related guides

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