utils: add little-endian swap helpers
[project/libubox.git] / sh / jshn.sh
index 0b0c754..1d9fc80 100644 (file)
@@ -103,7 +103,7 @@ _json_add_table() {
        local table="JSON_$itype$seq"
        _json_export "UP_$table" "$cur"
        _json_export "KEYS_$table" ""
-       [ "$TYPE" = "ARRAY" ] && _json_export "SEQ_$table" ""
+       [ "$itype" = "ARRAY" ] && _json_export "SEQ_$table" ""
        _json_stack_push "$table"
 
        _json_get_var new_cur JSON_CUR
@@ -193,12 +193,12 @@ json_dump() {
 }
 
 json_get_type() {
-       local dest="$1"
-       local cur
+       local __dest="$1"
+       local __cur
 
-       _json_get_var cur JSON_CUR
-       local var="${JSON_PREFIX}TYPE_${cur}_$2"
-       eval "export -- \"$dest=\${$var}\"; [ -n \"\${$var+x}\" ]"
+       _json_get_var __cur JSON_CUR
+       local __var="${JSON_PREFIX}TYPE_${__cur}_${2//[^a-zA-Z0-9_]/_}"
+       eval "export -- \"$__dest=\${$__var}\"; [ -n \"\${$__var+x}\" ]"
 }
 
 json_get_var() {
@@ -244,3 +244,10 @@ json_select() {
                ;;
        esac
 }
+
+json_is_a() {
+       local type
+
+       json_get_type type "$1"
+       [ "$type" = "$2" ]
+}