Linux命令行(Console)解析JSON

有些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 jq
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
Name        : jq
Arch        : x86_64
Version     : 1.5
Release     : 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
img_1c8d229764635ccdb8e96d36c40352e3.png
使用jq

总结

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值