Filtering values from Json format without jq

Im checking inside a openwrt to see If is possible to filter json string to have the values.

For example {"address":"","user":"user1","groups":"permissions"}

I receive from curl the string and I need to separate values to pass vars to other commands.

For now Im checking some examples but not works

. /usr/share/libubox/ 
json_load '$(cat $STRING)'
json_get_keys keys
for k in $keys; do 
   json_get_var v "$k"
   echo "$k : $v"

But produce error "Failed to parse message data"

My problem is justly that I can't use jq, or python to choose data, so I think the solution is to separate first and send to vars every value, making something usable. I was checking jshn and jsonfilter utilities but for this type of json not seems to work.


Google something like "bash split json" and you will find tons of examples on how to do that.


For now I detected first error

json_load '$(cat $RESPONSE)' needs to be

json_load $(echo $RESPONSE)

You can use OpenWrt’s builtin jsonfilter command.

eval $(jsonfilter -s '{"address":"","user":"user1","groups":"permissions"}' -e 'ADDRESS=@.address' -e 'USER=@.user')
echo "address=$ADDRESS user=$USER"
1 Like


I prefer this option to filter, but I never found the form to use -e option.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.