diff options
author | Felix Fietkau <nbd@openwrt.org> | 2013-10-29 18:11:42 +0400 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2013-10-29 18:11:42 +0400 |
commit | b7e61837e7269a8eafca280f904ab4a4e1425840 (patch) | |
tree | 4bb6de794a9fbfd5b4c8d6d5b55bb212e5228b58 /sh | |
parent | b5aa522f5dc00e9954b45a59a88a2f495feabd9e (diff) |
jshn: allow json_get_keys/values to refer to the currently selected array/table if no argument is given
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'sh')
-rw-r--r-- | sh/jshn.sh | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -218,25 +218,35 @@ json_get_keys() { local __dest="$1" local _tbl_cur - json_get_var _tbl_cur "$2" + if [ -n "$2" ]; then + json_get_var _tbl_cur "$2" + else + _json_get_var _tbl_cur JSON_CUR + fi local __var="${JSON_PREFIX}KEYS_${_tbl_cur}" eval "export -- \"$__dest=\${$__var}\"; [ -n \"\${$__var+x}\" ]" } json_get_values() { local _v_dest="$1" - local _v_keys _v_val + local _v_keys _v_val _select= unset "$_v_dest" - json_get_keys _v_keys "$2" - json_select "$2" + [ -n "$2" ] && { + json_select "$2" + _select=1 + } + + json_get_keys _v_keys set -- $_v_keys while [ "$#" -gt 0 ]; do json_get_var _v_val "$1" __jshn_raw_append "$_v_dest" "$_v_val" shift done - json_select .. + [ -n "$_select" ] && json_select .. + + return 0 } json_get_var() { |