Skip to content

how check if key or key and value exist in a file ?? #3140

Closed Answered by wader
markonop93 asked this question in Q&A
Discussion options

You must be logged in to vote
# using has/1
$ jq 'has("somekey")' <<< '{"somekey": 123}'
true

# if you know the key will never have the value null or false you can just do .somekey 
$ jq 'if .somekey then "yeap" else "nope" end' <<< '{"somekey": 123}'
"yeap"

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@markonop93
Comment options

Answer selected by pkoppstein
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants