Skip to content

check if key exists #250

Answered by TomWright
electriquo asked this question in Q&A
Oct 6, 2022 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

The - character when used in a dynamic/search selector can be used to check the key/property name in an array/object, however it doesn't work in this case.

Dasel returns an exit code of 1 if it failed to find the item though so I wonder if you could just run a basic selector and check the exit code?

~ [] $ echo '{"name":"Tom"}' | dasel -r json .name
"Tom"
~ [] $ echo $?
0
~ [] $ echo '{"name":"Tom"}' | dasel -r json .age
Error: could not query node: could not find value: no value found for selector: .age: map[name:Tom]
~ [] $ echo $?
1

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@electriquo
Comment options

@TomWright
Comment options

Answer selected by electriquo
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