Cheatsheet Pages / jq Cheatsheet
How to inspect and trim JSON object keys with jq — keys, has, del
You need to know what keys an object has, whether a specific one exists, or produce the object minus a field.
Every filter was executed against the cheatsheet's sample config.json with jq 1.7 before publishing; the sample file sits at the bottom of the cheatsheet so you can reproduce every output.
jq '.users[0] | keys' config.json
# output: ["active","age","city","name","role","score"]
jq '.users[0] | has("role")' config.json # -> true
jq -c 'del(.debug) | keys' config.json
# output: ["name","owner","port","tags","users","version"] (debug gone)
