From: Matthias Kruk Date: Tue, 6 Jul 2021 22:56:43 +0000 (+0900) Subject: include/json: Allow false booleans to be retrieved from JSON types X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=097109bfb7f0797c33beeadd6bf988b608a95e24;p=toolbox include/json: Allow false booleans to be retrieved from JSON types 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. --- diff --git a/include/json.sh b/include/json.sh index b9b0469..b60da1d 100644 --- a/include/json.sh +++ b/include/json.sh @@ -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