`jq -r '.items[].metadata.name'` fails with `jq: error (at <stdin>:1): Cannot iterate over null (null)`
IntermediateTroubleshootingTroubleshooting: quoting, expansion and tool-input bugs
Answer
Likely causes → .items does not exist or is null in this input: the API returned an error object, a single object instead of a list, or the field name is different (.Items, .data).
Diagnose →
cmd | jq 'keys' # what top-level keys exist?
cmd | jq '.items | type'
Fix → Fix the path, or handle absence explicitly: jq -r '.items[]?.metadata.name' or (.items // [])[]. If an error object came back, check the command's exit status before parsing.
Prevent → Check the producer's exit code, then parse; use jq -e when a missing value should fail the script.
More on Troubleshooting: quoting, expansion and tool-input bugs
`bash: [: too many arguments`Beginner`bash: [: =: unary operator expected`BeginnerA disk check fails with `[: 93%: integer expression expected`Beginner`rm $file` fails with `rm: cannot remove 'monthly': No such file or directory` and `rm: cannot remove 'report.csv'`.BeginnerA cleanup script logs `cp: cannot stat '/var/log/app/*.log': No such file or directory` on quiet days.Beginner`echo "start" > $logfile` fails with `bash: $logfile: ambiguous redirect`Intermediate