安装
yum install -y libtool && \
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-1.5.tar.gz && \
tar -xf jq-1.5.tar.gz -C /usr/local && \
cd /usr/local/jq-1.5 && \
./configure --disable-maintainer-mode && \
make LDFLAGS=-all-static && \
make install && \
cp /usr/local/jq-1.5/jq /sbin/ \
echo "程序已安装: `which jq`"
举个栗子,如:
我这里有个API请求,在终端中得到的结果是一串json字符串,但是看起来不是那么规整,一下子还很难判断是什么格式;
[root@localhost ~]# curl -s http://SERVER_IP/health/monitor/service
{"data":{"serCode":"0","serDesc":"服务正常"},"resultCode":1}
于是通过jq这个命令我们格式化一下,终端里面看到的结果就是下面这样的啦
[root@salt-api ~]# curl -s http://SERVER_IP/health/monitor/service | jq
{
"data": {
"serCode": "0",
"serDesc": "服务正常"
},
"resultCode": 1
}