Interview Prep/Shell Scripting/find, xargs, jq and yq

How do you transform JSON into CSV/TSV or group and aggregate with `jq`?

AdvancedConceptfind, xargs, jq and yq
Answer
# TSV of pods: namespace, name, node
kubectl get pods -A -o json |
  jq -r '.items[] | [.metadata.namespace, .metadata.name, .spec.nodeName // "-"] | @tsv'

# Count pods per node
kubectl get pods -A -o json |
  jq -r '.items | group_by(.spec.nodeName) | map({node: .[0].spec.nodeName, pods: length}) | .[] | "\(.node)\t\(.pods)"'

# Sum EBS volume sizes
aws ec2 describe-volumes | jq '[.Volumes[].Size] | add'

@csv quotes strings properly; @tsv escapes tabs; @sh quotes values for safe use in shell commands.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on find, xargs, jq and yq