为了账号安全,请及时绑定邮箱和手机立即绑定

Linux命令行(Console)解析JSON

标签:
Linux

有些Linux服务API返回的数据为JSON数据,但是直接在命令行看,看起来很不方便,都拧巴在一起了,比如这样。

[root@songshucang nginx]# curl http://localhost:8500/v1/catalog/service/xxx[{"ID":"5c82060b-caa6-082c-27ac-4e64d38d35f1","Node":"izwz99ridy7gp33ry7hmfqz","Address":"172.18.177.227","Datacenter":"default","TaggedAddresses":{"lan":"172.18.177.227","wan":"172.18.177.227"},"NodeMeta":{"consul-network-segment":""},"ServiceID":"application-ecs-8090","ServiceName":"songshu-cang","ServiceTags":["songshu"],"ServiceAddress":"172.18.177.227","ServicePort":8090,"ServiceEnableTagOverride":false,"CreateIndex":502,"ModifyIndex":502},{"ID":"5c82060b-caa6-082c-27ac-4e64d38d35f1","Node":"izwz99ridy7gp33ry7hmfqz","Address":"172.18.177.227","Datacenter":"default","TaggedAddresses":{"lan":"172.18.177.227","wan":"172.18.177.227"},"NodeMeta":{"consul-network-segment":""},"ServiceID":"application-ecs-8091","ServiceName":"songshu-cang","ServiceTags":["songshu"],"ServiceAddress":"172.18.177.227","ServicePort":8091,"ServiceEnableTagOverride":false,"CreateIndex":520,"ModifyIndex":520}][root@songshucang nginx]#

不过Linux内置了一些命令,比如jq

[root@songshucang nginx]# yum info jqLoaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
Name        : jq
Arch        : x86_64
Version     : 1.5Release     : 1.el7
Size        : 351 k
Repo        : installed
From repo   : epel
Summary     : Command-line JSON processor
URL         : http://stedolan.github.io/jq/
License     : MIT and ASL 2.0 and CC-BY and GPLv3
Description : lightweight and flexible command-line JSON processor
            :
            :  jq is like sed for JSON data – you can use it to slice
            :  and filter and map and transform structured data with
            :  the same ease that sed, awk, grep and friends let you
            :  play with text.
            :
            :  It is written in portable C, and it has zero runtime
            :  dependencies.
            :
            :  jq can mangle the data format that you have into the
            :  one that you want with very little effort, and the
            :  program to do so is often shorter and simpler than
            :  you'd expect.

安装与使用jq

sudo yum install jq -y

1000

使用jq

总结

简单的介绍了一个Linux的命令。

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
JAVA开发工程师
手记
粉丝
1.1万
获赞与收藏
1544

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消