jq / yq
jq
Flags
| Flag | Effect |
|---|---|
-r | Raw output β strips JSON string quotes |
-c | Compact output (single line) |
-e | Exit non-zero if last output is false or null |
-n | No input β use null as input (useful with --arg) |
-s | Slurp β read all inputs into a single array |
--arg name val | Bind shell string to $name |
--argjson name val | Bind parsed JSON to $name |
--rawfile name file | Bind raw file content to $name |
Field access
Arrays
Select / filter
Transform / reshape
Modify
Variables & args
yq
Two distinct yq packages
There are two unrelated yq tools β make sure you know which one you have:
- kislyuk/yq β Python wrapper around
jq. Uses jq syntax. Pass-yto output YAML. - mikefarah/yq β Standalone Go tool. Uses its own syntax (similar to jq but different).
The examples below cover both. Check yours with yq --version.
kislyuk/yq (jq wrapper)
kislyuk/yq reads YAML as input and runs a jq filter. Use -y to write YAML output instead of JSON.
mikefarah/yq
mikefarah/yq uses a path expression syntax inspired by jq but with differences (e.g. | behaves differently, use .* to iterate maps).