+
+json_get() {
+ local json="$1" jpath="${2#.}" id idx
+ json_type=''
+
+ case $json in
+ str:*) json_type="string";;
+ arr:*) json_type="array";;
+ obj:*) json_type="object";;
+ num:*) json_type="number";;
+ true|false)
+ json_type="boolean";;
+ null) json_type="null";;
+ esac
+ json="${json#???:}"
+
+ case $jpath in
+ "")
+ printf %s\\n "$json"
+ return 0
+ ;;
+ "["[0-9]*"]"*)
+ idx="${jpath%%"]"*}" idx="${idx#"["}"
+ jpath="${jpath#"["*"]"}"
+ ;;
+ "['"*"']"*)
+ id="${jpath%%"']"*}" id="${id#"['"}"
+ jpath="${jpath#"['"*"']"}"
+ ;;
+ *) id="${jpath%%[".["]*}"
+ jpath="${jpath#"$id"}"
+ ;;
+ esac
+
+ if [ "$id" -a "$json_type" = object ]; then
+ # if ! json="$(DB2 "$(UNSTRING "$json")" get "$id")"; then
+ if ! json="$(DB2 "$json" get "$id")"; then
+ debug "No key: \"$id\""
+ return 1
+ fi
+ elif [ "$idx" -a "$json_type" = array ]; then
+ if ! json="$(DB2 "$(UNSTRING "$json")" get @ "$(( idx + 1 ))")"; then
+ # if ! json="$(DB2 "$json" get @ "$(( idx + 1 ))")"; then
+ debug "No array index: \"$idx\""
+ return 1
+ fi
+ else
+ debug "Value type missmatch"
+ return 1
+ fi
+ json_get "$json" "$jpath"
+ return $?
+}