使用GET时过滤结果

时间:2019-01-09 22:59:10

标签: json bash

执行此命令时,我只希望获得一个参数:

curl -X GET http://${HUE}/api/${API}/lights/1

我只需要显示在此参数中看到的 true / false {“ state”:{“ on”:

如何修改GET以仅显示此结果而不显示实际结果?

{"state":{"on":true,"bri":90,"alert":"select","mode":"homeautomation","reachable":true},"swupdate":{"state":"noupdates","lastinstall":"2019-01-04T22:37:21"},"type":"Dimmable light","name":"Bombeta menjador 1","modelid":"LWB010","manufacturername":"Philips","productname":"Hue white lamp",...

1 个答案:

答案 0 :(得分:1)

如果这是有效的json并且您可以访问jq实用程序,则可以:

curl .... | jq --compact-output '.state.on'

根据值将输出truefalse