首页 > 解决方案 > Filter result when use GET

问题描述

I like to get only one parameter when execute this command:

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

I need only to show true/false that see in this parameter {"state":{"on":

How can modify the GET to show only this instead the actual result?

{"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",...

标签: jsonbash

解决方案


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

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

这将输出truefalse取决于值。


推荐阅读