3 # [ -n "$include_json" ] && return 0
6 . "${_EXEC:-.}/cgilite/db23.sh"
9 printf '%s\n' "$@" >&2;
10 printf 'Exc: %s\n' "$json_document" >&2
14 while true; do case "$json_document" in
15 [" ${BR}${CR} "]*) json_document="${json_document#?}";;
21 local string json_document="$json_document" end=0
24 case $json_document in
25 \"*) json_document="${json_document#?}"
27 *) json_except "Expected string specifyer starting with (\")"
31 while [ "$json_document" ]; do case $json_document in
33 string="${string}${json_document%"${json_document#??}"}"
34 json_document="${json_document#??}"
37 json_document="${json_document#?}"
42 string="${string}${json_document%"${json_document#?}"}"
43 json_document="${json_document#?}"
47 if [ $end -eq 0 ]; then
48 json_except "Document ended mid-string"
52 printf "%s %s\n" "$(STRING "$string")" "$json_document"
56 local key json_document="$json_document"
59 case $json_document in
61 key="$(json_string)" || return 1
62 json_document="${key#* }"
65 *) json_except "Expected key specifyer starting with '\"'"
70 case $json_document in
71 :*) json_document="${json_document#?}"
73 *) json_except "Expected value separator \":\""
78 printf '%s %s\n' "$key" "$json_document"
82 local number json_document="$json_document"
85 number="${json_document%%[" ${BR}${CR} ,}]"]*}"
86 json_document="${json_document#"$number"}"
87 if ! number="$(printf %f "$number")"; then
88 json_except "Invalid number format"
92 printf '%s %s\n' "num:${number%.000000}" "$json_document"
96 local value json_document="$json_document"
99 case $json_document in
101 value="$(json_string)" || return 1
102 json_document="${value#* }"
103 value="str:${value%% *}"
106 value="$(json_number)" || return 1
107 json_document="${value#* }"
111 value="$(json_object)" || return 1
112 json_document="${value#* }"
113 value="obj:${value%% *}"
116 value="$(json_array)" || return 1
117 json_document="${value#* }"
118 value="arr:${value%% *}"
121 json_document="${json_document#null}"
125 json_document="${json_document#true}"
129 json_document="${json_document#false}"
134 printf "%s %s\n" "$value" "$json_document"
138 local struct="$(DB2 new)" value json_document="$json_document"
141 case $json_document in
142 "["*) json_document="${json_document#?}"
144 *) json_except "Expected array starting with \"[\""
150 case $json_document in
152 printf "%s %s\n" "" "${json_document#?}"
160 value="$(json_value)" || return 1
161 json_document="${value#* }"
162 value="$(UNSTRING "${value%% *}")"
164 struct="$(DB2 "$struct" append "@" "$value")" \
165 || struct="$(DB2 "$struct" set "@" "$value")"
168 case $json_document in
169 ,*) json_document="${json_document#?}"
171 "]"*) json_document="${json_document#?}"
174 *) json_except "Unexpected character mid-array"
180 printf "%s %s\n" "$(STRING "$struct")" "$json_document"
184 local struct="$(DB2 new)" key value json_document="$json_document"
187 case $json_document in
188 "{"*) json_document="${json_document#?}"
190 *) json_except "Expected object starting with \"{\""
196 case $json_document in
198 printf "%s %s\n" "" "${json_document#?}"
206 key="$(json_key)" || return 1
207 json_document="${key#* }"
208 key="$(UNSTRING "${key%% *}")"
210 value="$(json_value)" || return 1
211 json_document="${value#* }"
212 value="$(UNSTRING "${value%% *}")"
214 struct="$(DB2 "$struct" set "$key" "$value")"
217 case $json_document in
218 ,*) json_document="${json_document#?}"
220 "}"*) json_document="${json_document#?}"
223 *) json_except "Unexpected character mid-object"
229 printf "%s %s\n" "$(STRING "$struct")" "$json_document"
233 local json_document="$1"