Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2013-10-29 17:59:47 +0400
committerFelix Fietkau <nbd@openwrt.org>2013-10-29 17:59:47 +0400
commitb5aa522f5dc00e9954b45a59a88a2f495feabd9e (patch)
treef90331ffd8cfda934c6346577e68e641d4c51cf1 /sh
parenta2453456f2942e04d2b2caaf324aa0b7c2ed74eb (diff)
jshn: add json_get_values (useful for arrays)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'sh')
-rw-r--r--sh/jshn.sh25
1 files changed, 25 insertions, 0 deletions
diff --git a/sh/jshn.sh b/sh/jshn.sh
index 110892c..e919910 100644
--- a/sh/jshn.sh
+++ b/sh/jshn.sh
@@ -12,6 +12,15 @@ _json_set_var() {
eval "${JSON_PREFIX}$___var=\"\$___val\""
}
+__jshn_raw_append() {
+ local var="$1"
+ local value="$2"
+ local sep="${3:- }"
+
+ eval "export -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
+}
+
+
_jshn_append() {
local __var="$1"
local __value="$2"
@@ -214,6 +223,22 @@ json_get_keys() {
eval "export -- \"$__dest=\${$__var}\"; [ -n \"\${$__var+x}\" ]"
}
+json_get_values() {
+ local _v_dest="$1"
+ local _v_keys _v_val
+
+ unset "$_v_dest"
+ json_get_keys _v_keys "$2"
+ json_select "$2"
+ set -- $_v_keys
+ while [ "$#" -gt 0 ]; do
+ json_get_var _v_val "$1"
+ __jshn_raw_append "$_v_dest" "$_v_val"
+ shift
+ done
+ json_select ..
+}
+
json_get_var() {
local __dest="$1"
local __cur