]> git.corax.cc Git - toolbox/commitdiff
include/json: Allow false booleans to be retrieved from JSON types
authorMatthias Kruk <m@m10k.eu>
Tue, 6 Jul 2021 22:56:43 +0000 (07:56 +0900)
committerMatthias Kruk <m@m10k.eu>
Tue, 6 Jul 2021 22:56:43 +0000 (07:56 +0900)
Because of the way the return value of jq is checked in
json_object_get() and json_array_head(), the functions will fail if a
value of (boolean) "false" was retrieved from the JSON type.
This commit fixes the behavior of json_object_get() and
json_array_head() so that false booleans can be retrieved.

include/json.sh

index b9b0469bfb6e3b452e4afaa93c1e668b362a5f0c..b60da1d6fc11fd81263bf85352c8a1949a9b34e0 100644 (file)
@@ -86,7 +86,9 @@ json_object_get() {
 
        local value
 
-       if ! value=$(jq -e -r ".$field" <<< "$object"); then
+       value=$(jq -e -r ".$field" <<< "$object")
+
+       if (( $? > 1 )); then
                return 1
        fi
 
@@ -143,7 +145,9 @@ json_array_head() {
 
        local head
 
-       if ! head=$(jq -e -r '.[0]' <<< "$array"); then
+       head=$(jq -e -r '.[0]' <<< "$array")
+
+       if (( $? > 1 )); then
                return 1
        fi