freeboxos / freeboxos-bash-api

Access FreeboxOS API from bash
GNU General Public License v3.0
50 stars 11 forks source link

get json fails on some request #2

Closed ghost closed 10 years ago

ghost commented 10 years ago

for example, after asking for xdsl: answer=$(call_freebox_api '/connection/xdsl') result=$(get_json_value_for_key "$answer" 'result')

get_json_value_for_key "$result" 'down' will return something like: {"es":45,"phyr":true,"attn":51,"snr":6,"nitro":true,"rate":3315,"hec":0,"crc":2,"rxmt_uncorr":8,"rxmt_corr":8,"ses":38,"fec":3493530,"maxrate":4188,"rxmt":99751},"up":{"es":3,"phyr":false,"attn":26,"snr":7,"nitro":true,"rate":1025,"hec":0,"crc":0,"rxmt_uncorr":0,"rxmt_corr":0,"ses":3,"fec":1241,"maxrate":985,"rxmt":0}

we have 'up' value following 'down' value

get_json_value_for_key "$result" 'status' will return showtime instead of {"status":"showtime","protocol":"adsl2plus_a","uptime":3648282,"modulation":"adsl"}

Why do you not use jq functions? or propose to use it?

BTW, this is a very usefull tool. Thanks a lot

JrCs commented 10 years ago

What do you call jq functions ?

ghost commented 10 years ago

I installed the packet jq on ubuntu and debian. It is a easy tool to parse json values

ghost commented 10 years ago

For example, you can use: $ echo $answer | jq '.result.down.maxrate' 4188 $ echo $answer | jq '.result.down' { "rxmt": 101222, "maxrate": 4149, "fec": 3510031, "ses": 38, "rxmt_corr": 8, "rxmt_uncorr": 8, "es": 45, "phyr": true, "attn": 51, "snr": 5, "nitro": true, "rate": 3315, "hec": 0, "crc": 2 }

JrCs commented 10 years ago

Thanks for the information, but the script is made to be use in any unix system. It is written entirely in pure bash and must not use any specific external commands. I currently working on a new version that would be parse correctly json data.

ghost commented 10 years ago

What do you think do directly use a working tool as : https://github.com/kristopolous/TickTick ?

JrCs commented 10 years ago

I will use a mix between ticktick and json.sh

ghost commented 10 years ago

Great, I will follow and help if needed.

JrCs commented 10 years ago

Done in 527b24b5a88fe17397391d2f74e7c2559cf2851c Also i have add a new function dump_json_keys_values.