check if key exists #250
Answered
by
TomWright
electriquo
asked this question in
Q&A
-
Although I browsed search and search optional documentation, I did not find how to check whether a key exists (a functionality which is equivalent to jq The motivation:
|
Beta Was this translation helpful? Give feedback.
Answered by
TomWright
Oct 6, 2022
Replies: 1 comment 2 replies
-
The Dasel returns an exit code of ~ [] $ 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 |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
electriquo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?