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"
39 json_add_generic object "$1" "$JSON_CUR" "$cur"
43 local oldstack="$JSON_STACK"
44 export "KEYS_${JSON_CUR}"
45 JSON_CUR="${JSON_STACK##* }"
46 JSON_STACK="${JSON_STACK% *}"
47 [[ "$oldstack" == "$JSON_STACK" ]] && JSON_STACK=
53 json_add_generic array "$1" "$JSON_CUR" "$cur"
61 json_add_generic string "$1" "$2"
65 json_add_generic int "$1" "$2"
69 json_add_generic boolean "$1" "$2"
72 # functions read access to json variables
85 eval "export -- \"$dest=\${TYPE_${JSON_CUR}_$var}\""
91 eval "export -- \"$dest=\${${JSON_CUR}_$var}\""
102 [[ "$1" == ".." ]] && {
103 eval "JSON_CUR=\"\${UP_$JSON_CUR}\""
106 json_get_type type "$target"
109 json_get_var JSON_CUR "$target"
112 echo "WARNING: Variable '$target' does not exist or is not an array/object"