概述
有三种方式
一、Python 格式化
在curl命令后面添加 | python -m json.tool 即可。
➜
views git:(master) ✗ curl -g 'http://10.4.110.138:9090/api/v1/series?match[]=up&match[]=process_start_time_seconds{job="prometheus"}' | python -m json.tool
% Total
% Received % Xferd
Average Speed
Time
Time
Time
Current
Dload
Upload
Total
Spent
Left
Speed
100
183
100
183
0
0
27568
0 --:--:-- --:--:-- --:--:-- 30500
{
"data": [
{
"__name__": "process_start_time_seconds",
"instance": "localhost:9090",
"job": "prometheus"
},
{
"__name__": "up",
"instance": "localhost:9090",
"job": "prometheus"
}
],
"status": "success"
}
二、Nodejs 格式化
安装json命令
npm install -g json
在curl命令后面添加 | json 即可。
例如:
views git:(master) ✗ curl -g 'http://10.4.110.138:9090/api/v1/series?match[]=up&match[]=process_start_time_seconds{job="prometheus"}' | json
% Total
% Received % Xferd
Average Speed
Time
Time
Time
Current
Dload
Upload
Total
Spent
Left
Speed
100
183
100
183
0
0
31250
0 --:--:-- --:--:-- --:--:-- 36600
{
"status": "success",
"data": [
{
"__name__": "process_start_time_seconds",
"instance": "localhost:9090",
"job": "prometheus"
},
{
"__name__": "up",
"instance": "localhost:9090",
"job": "prometheus"
}
]
}
第三中
通过jq工具
curl -g 'http://10.4.110.138:9090/api/v1/series?match[]=up&match[]=process_start_time_seconds{job="prometheus"}' | jq .
% Total
% Received % Xferd
Average Speed
Time
Time
Time
Current
Dload
Upload
Total
Spent
Left
Speed
100
183
100
183
0
0
25771
0 --:--:-- --:--:-- --:--:-- 30500
{
"status": "success",
"data": [
{
"__name__": "process_start_time_seconds",
"instance": "localhost:9090",
"job": "prometheus"
},
{
"__name__": "up",
"instance": "localhost:9090",
"job": "prometheus"
}
]
}
参考:
格式化Curl返回的Json字符
最后
以上就是糟糕猎豹为你收集整理的格式化Curl返回的Json字符(转)的全部内容,希望文章能够帮你解决格式化Curl返回的Json字符(转)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复