[OpenWrt-Devel] Jsonfilter, return partial subobject?

Michael Jones mike at meshplusplus.com
Thu Apr 23 14:18:45 EDT 2020

On Thu, Apr 23, 2020 at 12:55 PM Michael Jones <mike at meshplusplus.com>

> I'm quite reluctant to do multiple processing sweeps. E.g. the following
> (probably syntax-error-full, and erroneous output) shell script is
> extremely unattractive
> json=`ubus call network.interface dump | jsonfilter -e '@.interface'`
> echo '['
> for itf in $(echo $json | jsonfilter -e '@[@.up=true].interface')
> do
>     echo "{ \"interface\" : \"$itf\" , \"uptime\" : $(echo $json |
> jsonfilter -e "@[@.interface=$itf].uptime") }," # Oh look, an unconditional
> trailing comma... that won't parse until JSON5...
> done
> echo ']'
I suppose I should follow my original email up with an acknowledgement of
the jshn.sh library (and jshn program).

So I know that the script could be improved to work (and work correctly)
like this:

. /usr/share/libubox/jshn.sh
json_add_array arr

jsonoutput=`ubus call network.interface dump | jsonfilter -e '@.interface'`

for itf in $(echo $jsonoutput | jsonfilter -e '@[@.up=true].interface')
    json_add_string interface $itf
    json_add_int    uptime    $(echo $jsonoutput | jsonfilter -e

json_dump | jsonfilter -e '@.arr'

But I didn't want to muddle the question of "can I do what I want with
jsonfilter by itself", because I don't want to involve the use of a shell
script at all if I can avoid it!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20200423/5f0e582b/attachment.htm>
-------------- next part --------------
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list