3

I have an IP camera with armv5tejl architecture. There I have busybox. I have to be able to parse JSON responses from curl. The problem is that I don't have programs like:
jq, jshon, jsawk...
It is hard to instal them for this architecture. I have to find some shell script which can parse JSON object and JSON array.

If it is possible to find this script, please, show me that script

3
  • what about perl?
    – Jeff Schaller
    Jul 27, 2016 at 17:28
  • Don't have neither perl nor python. I have to find some solution with awk, sed, grep and so on..
    – Oleksandr
    Jul 27, 2016 at 17:30
  • 2
    jq should not be hard to compile from source, it only needs bison and flex
    – grochmal
    Jul 27, 2016 at 19:32

3 Answers 3

4

You have ash or bash so you can use json.sh. You have awk so you can use json.awk.

2
  • Yes. Thank you for help. I have found json.awk just several minutes ago)
    – Oleksandr
    Jul 27, 2016 at 20:16
  • json.sh also works with ash
    – Oleksandr
    Jul 27, 2016 at 20:34
2

As grochmal said. There is jq which is pretty good but I couldn't compile it.
Also we can just use JSON.awk to parse json (is not very convenient but works). Example:

echo -e jsonFile | awk -f JSON.awk

To get necessary keys and values we can grep output. Example (parse json response with google drive folders to find all ids of folders):

echo -e jsonResponse | awk -f JSON.awk | egrep '\["items",[0-9]+,"id"\]' 
1

Sure the best way today in 2023 to parse json in busybox (and when you CANNOT install foreign programs) is to use function from JSON.sh

Parsing is quiete slow when curl return a big and complex json (more than 80 kb) but I'm working on to make it faster... if you're interested, follow on the github.com project

And as this post is years old, I'm posting today to confirm that in 2023 and after a long search and a lot of tests, I did not find any better bash only json parsing library (It handle nearly all cases of stranges characters, strings... you can encountered in a reply of curl which is a json formatted string), so it work in nearly all cases.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .