From 097109bfb7f0797c33beeadd6bf988b608a95e24 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Wed, 7 Jul 2021 07:56:43 +0900 Subject: [PATCH] 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. --- include/json.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 -- 2.47.3