Json parser for shell script
-
I am trying to write some shell scripts to react to some sensors. However, the output of the sensor is in Json format.
Is there any Json parser I could use ? I'd tried jq but the compiled version doesn't seems to work and I really don't want to use Python due to memory constrain. Any other idea?
Thanks in advance!
-
Did you have a look in the wiki? wiki.onion.io
There you might find some infos ... be aware that this wiki was made for omega1
-
@Luciano-S. Thanks for the feedback, I checked it but it seems the only project involving Json using Python to do the parsing job....
Actually I want to use jq since my scripts runs well on a Rpi with jq. Thus I want to find at least a jq alternative. Also Omega2' s memory is too small for compiling jq and pre- compiled binary doesn't work... (Cross compiling is doable but if that's not for a faint of heart...)
-
@Ls-Song , you could probably do a issue on Github and asking if they could compile for you. Or did you try on the cloud?
It sounds that you use a omega1? the omega2+ comes with 128MB would this be still not enough?
-
@Luciano-S. I am on Omega2+ and I have some stuff already put inside the omega... I think maybe I need follow your suggestion and put a request on Git...
Thanks..
-
You can find http://downloads.lede-project.org/snapshots/packages/mipsel_24kc/packages/jq_1.5-2_mipsel_24kc.ipk
You should enable the other available repositories. Here's my working distfeeds.conf:
src/gz reboot_core http://downloads.lede-project.org/snapshots/targets/ramips/mt76x8/packages
src/gz reboot_base http://downloads.lede-project.org/snapshots/packages/mipsel_24kc/base
src/gz reboot_luci http://downloads.lede-project.org/snapshots/packages/mipsel_24kc/luci
src/gz reboot_packages http://downloads.lede-project.org/snapshots/packages/mipsel_24kc/packages
src/gz reboot_routing http://downloads.lede-project.org/snapshots/packages/mipsel_24kc/routing
src/gz reboot_telephony http://downloads.lede-project.org/snapshots/packages/mipsel_24kc/telephony
src/gz omega2_core http://repo.onion.io/omega2/packages/core
src/gz omega2_base http://repo.onion.io/omega2/packages/base
src/gz omega2_packages http://repo.onion.io/omega2/packages/packages
src/gz omega2_onion http://repo.onion.io/omega2/packages/onion
-
Do you need something that is fully Json compliant, or something to work on simple key-value pairs. I wrote the following. It has worked, but no guarantees.
use: json json-string key default
json(){
a=$(echo "$1" | sed -E 's/[{}]/,/g; s/ *([:,]) /\1/g; s/"//g' | grep -oE ",$2:[^,]")
if [ -z "$a" ]; then
echo "$3"
else
echo "$a" | cut -d : -f 2
fi
}