Search for keys in JSON at any level containing the supplied string and strips out any empty results
cat some-json | jq -c '.. | objects | with_entries(select(.key |match("SEARCH-STRING";"i"))) | select(. != {})'
For instance, to list any keys that contain the word public
from a list of AWS instances :
aws ec2 describe-instances --output json | jq -c '.. | objects | with_entries(select(.key |match("public";"i"))) | select(. != {})'
Outputs:
{"PublicDnsName":"xxxxx.compute-1.amazonaws.com","PublicIpAddress":"xx.xx.xx.xx"}
{"PublicDnsName":"xxxxx.compute-1.amazonaws.com","PublicIp":"xx.xx.xx.xx"}
{"PublicDnsName":"xxxxx.amazonaws.com","PublicIp":"xx.xx.xx.xx"}