json - 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",...
解决方案
如果这是一个有效的 json 并且您可以访问jq
实用程序,您可以:
curl .... | jq --compact-output '.state.on'
这将输出true
或false
取决于值。
推荐阅读
- flutter - 如何在 Flutter 中用点填充两个文本元素之间的空间
- reactjs - Postman 中的 REST API 可以工作,但不能在 REACTJS 应用程序中使用 AXIOS 进行 POST 请求
- c# - 关于适当数据结构的建议
- anylogic - AnyLogic 有没有办法在 GIS 地图中显示代理链接?
- java - Spring工具套件未显示创建方法是什么原因
- python - 如何禁用组合框中的特定索引/es或项目/s?
- node.js - 我需要管理员权限才能移动文件(node.js)
- javascript - Wordpress - .js 文件加载但什么也不做
- c - while 循环和 getchar() - 大输入
- java - 在没有 Main 方法的 Java 类库中从文件中读取数据