summaryrefslogtreecommitdiffstats
path: root/applications/luci-app-https-dns-proxy/tests/stubs/usr/share/libubox/jshn.sh
blob: 9614ea621caa5c5ac3a8770bcf2b11f21608bef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
# Minimal jshn stub for list command
__json_items=""
__json_cur=""
__json_depth=0
json_init() { __json_items=""; __json_cur=""; __json_depth=0; }
json_add_object() {
	if [ $__json_depth -eq 0 ]; then
		__json_cur="\"$1\":{"
	else
		__json_cur="${__json_cur}\"$1\":{"
	fi
	__json_depth=$((__json_depth+1))
}
json_add_string() { __json_cur="${__json_cur}\"$1\":\"$2\","; }
json_close_object() {
	__json_cur="${__json_cur%,}}"
	__json_depth=$((__json_depth-1))
	if [ $__json_depth -eq 0 ]; then
		__json_items="${__json_items:+${__json_items},}${__json_cur}"
		__json_cur=""
	else
		__json_cur="${__json_cur},"
	fi
}
json_dump() { echo "{${__json_items}}"; }
json_cleanup() { __json_items=""; __json_cur=""; }