JQ Free CheatSheet


- PDF Link: cheatsheet-jq-A4.pdf, Category: tools
- Blog URL: https://cheatsheet.dennyzhang.com/cheatsheet-jq-A4
- Related posts: Vim CheatSheet, #denny-cheatsheets
1.1 jq – parse json
Name | Command |
---|---|
jq remove double-quotes | Use the -r option to emit raw strings. jq -r ... |
yq | yq is a lightweight and portable command-line YAML processor |
Install yq | |
Write output to a file after piped to jq | some pipe -> jq . > /tmp/test.txt |
curl $es_ip:9200/$index_name/_stats?pretty | jq '._all.primaries' curl $es_ip:9200/$index_name/_stats?pretty | jq '._all.primaries | .docs, .merges, .segments' curl $es_ip:9200/$index_name/_stats?pretty | jq '.[0] | ._all: promaries}' curl $es_ip:9200/$index_name/_stats?pretty | jq '._all.primaries.docs[]' curl $es_ip:9200/$index_name/_stats?pretty | jq '._all.primaries.docs[], ._all.primaries.segments[]' curl $es_ip:9200/$index_name/_stats?pretty | jq '._all.primaries[]' | jq '.docs'
1.2 jq with watch
watch -n 0.5 "kubectl get configmaps map1 -o json | jq '.data[\"file1.conf\"]'" watch "curl $es_ip:9200/$index_name/_stats?pretty | jq '._all.primaries | .docs, .merges, .segments'"
1.3 k8s jq
# List pods and containers kubectl get pods -o='custom-columns=PODS:.metadata.name,CONTAINERS:.spec.containers[*].name' # List pods, containers and images kubectl get pods -o='custom-columns=PODS:.metadata.name,CONTAINERS:.spec.containers[*].name,Images:.spec.containers[*].image'
1.4 yq – parse yaml
Name | Command |
---|---|
yq | yq is a lightweight and portable command-line YAML processor |
Install yq | |
yq parse fields | yq r testbed.yaml my_ip |
1.5 parse yaml with pipelines
cat test.yaml | yq - r my_ip