What is `jq` and what are the filters you use every day?
BeginnerConceptfind, xargs, jq and yq
Answer
jq is a command-line JSON processor.
jq '.' file.json # pretty-print and validate
jq -r '.metadata.name' pod.json # raw string, no quotes
jq '.items[] | .metadata.name' # iterate an array
jq '.items | length' # count
jq '.items[] | select(.status.phase != "Running") | .metadata.name'
jq -r '.Reservations[].Instances[] | [.InstanceId, .State.Name] | @tsv'
jq '.spec.replicas = 3' deploy.json # modify
jq -e '.ready == true' status.json # exit 1 if false or null
-r (raw output) is what you want when the value feeds another command.
More on find, xargs, jq and yq
What are the most useful `find` predicates for operations work?BeginnerWhat is the difference between `-exec cmd {} \;`, `-exec cmd {} +` and `-delete`?IntermediateHow does `find` evaluate `-o` (OR) and why do you need parentheses?AdvancedWhat does `xargs` do, and which flags matter?IntermediateWhy is `find | xargs rm` dangerous and what is the safe form?IntermediateHow do you pass shell variables into `jq` safely?Intermediate