1 # functions for parsing and generating json
8 eval "export -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
12 [ -n "$JSON_UNSET" ] && eval "unset $JSON_UNSET"
13 export -- JSON_SEQ
=0 JSON_STACK
= JSON_CUR
="JSON_VAR" JSON_UNSET
=
20 local cur
="${4:-$JSON_CUR}"
22 export -- "${cur}_$var=$val"
23 export -- "TYPE_${cur}_$var=$type"
24 jshn_append JSON_UNSET
"${cur}_$var TYPE_${cur}_$var"
25 jshn_append
"KEYS_${cur}" "$var"
29 JSON_SEQ
=$
(($JSON_SEQ + 1))
30 jshn_append JSON_STACK
"$JSON_CUR"
31 local table
="JSON_TABLE$JSON_SEQ"
32 export -- "UP_$table=$JSON_CUR"
33 export -- "KEYS_$table="
34 jshn_append JSON_UNSET
"KEYS_$table UP_$table"
41 json_add_generic object
"$1" "$JSON_CUR" "$cur"
45 local oldstack
="$JSON_STACK"
46 JSON_CUR
="${JSON_STACK##* }"
47 JSON_STACK
="${JSON_STACK% *}"
48 [[ "$oldstack" == "$JSON_STACK" ]] && JSON_STACK
=
54 json_add_generic array
"$1" "$JSON_CUR" "$cur"
62 json_add_generic string
"$1" "$2"
66 json_add_generic int
"$1" "$2"
70 json_add_generic boolean
"$1" "$2"
73 # functions read access to json variables
86 eval "export -- \"$dest=\${TYPE_${JSON_CUR}_$var}\""
92 eval "export -- \"$dest=\${${JSON_CUR}_$var}\""
103 [[ "$1" == ".." ]] && {
104 eval "JSON_CUR=\"\${UP_$JSON_CUR}\""
107 json_get_type
type "$target"
110 json_get_var JSON_CUR
"$target"
113 echo "WARNING: Variable '$target' does not exist or is not an array/object"