[OpenWrt-Devel] Jsonfilter, return partial subobject?

Jo-Philipp Wich jo at mein.io
Thu Apr 23 16:49:46 EDT 2020


Hi,

> [...]
> What I want to do is return a JSON string with this representation:
> [
>     { "interface" : "lan", "uptime" : 11111 },
>     ...
> ]
> 
> E.g., I want to filter the json not down to a single value, but to a
> collection of key-value pairs by excluding items that don't match.

that is not directly possible. You can use the shell export mode together with
the field separator to build a list of tuples safe for processing, printf the
intermediate fields and finally use the array mode to build a proper list:

-- 8< --
eval $(ubus call network.interface dump | \
 jsonfilter -F ': ' -e 'tuples=@.interface[@.up=true]["interface","uptime"]')

for tuple in $tuples; do
 printf '{ "%s": %d }\n' "${tuple%:*}" "${tuple#*:}"
done | jsonfilter -a -e @
-- >8 --

Will result in something like the output below:

[ { "lan": 4409874 }, { "loopback": 4409873 }, { "modem": 803939 }, { "wan":
4040845 }, { "wan6": 2681477 } ]


Returning subsets of objects is not directly supported unfortunately but I'll
think about how to add something like this if I find the time.

~ Jo

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20200423/534f4792/attachment.sig>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list