zc-workstationDocumentation PDF GitHub

jq and yq

jq and yq, query and edit JSON and YAML from the command line.

.md

jq filters JSON: pick fields, select items, reshape the output. yq does the same for YAML with the same expression language, and converts between YAML and JSON. Together they read every -json output of zc-workstation and its YAML config.

On the workstation

  • Installed by the jq and yq formulae. yq is Mike Farah’s Go version.

  • gh takes the same expressions with --jq, so a GitHub query needs no pipe.

Keys and commands

Key or command Does

jq . file.json

Pretty-print JSON

jq -r '.[].name'

Print a field of every item, without quotes

jq '.[] | select(.x > 1)'

Keep the items that match

jq -s '.[0] * .[1]' a.json b.json

Merge two JSON files, the second winning

yq '.targets[].name' file.yaml

Query YAML

yq -i '.key = "value"' file.yaml

Edit YAML in place

yq -o json file.yaml

Convert YAML to JSON

With zc-workstation

The targets that are not fully in place:

$ zc-workstation status -json | jq -r '.[] | select(.in_place < .declared) | .summary'
41 of 43 dotfiles in place

Each planned change on one line:

$ zc-workstation plan -json | jq -r '.actions[] | "\(.op) \(.target) \(.resource)"'
UPDATE macos com.apple.finder FXPreferredViewStyle

The targets that run on Linux:

$ yq '.targets[] | select(.os[0] == "linux") | .name' zc-workstation.yaml
apt

Edit this page Last updated

Keyboard shortcuts

Ctrl/⌘ K or /
Search the docs
↑ ↓ Enter
Move through the search results
← →
Previous or next page
f
Filter the pages in the sidebar
g h
Home
t
Cycle the theme
?
This list
Esc
Close a menu or the search results