Because json_array_head() does not correctly check the return value
from jq, it does not correctly detect if an array is empty.
This commit fixes the function so that it does not rely on the return
value from `jq -e', since it returns an error if the boolean value false
was retrieved.
local array="$1"
local head
+ local string_re
- head=$(jq -e -r '.[0]' <<< "$array")
+ string_re='^"(.*)"$'
- if (( $? > 1 )); then
+ if ! head=$(jq '.[0]' <<< "$array") ||
+ [[ "$head" == "null" ]]; then
return 1
fi
- echo "$head"
+ if [[ "$head" =~ $string_re ]]; then
+ echo "${BASH_REMATCH[1]}"
+ else
+ echo "$head"
+ fi
+
return 0
}