在Unix Shell脚本中以可读JSON格式显示curl输出 [英] Display curl output in readable JSON format in Unix shell script
本文介绍了在Unix Shell脚本中以可读JSON格式显示curl输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Unix shell脚本中,当我执行curl命令时,结果将显示如下,我将其重定向到文件:
{ type: Show, id: 123, title: name, description: Funny, channelTitle: ifood.tv, lastUpdateTimestamp : 2014-04-20T20:34:59, numOfVideos: 15}
但是,我希望此输出以可读的JSON格式放在文件中,如下所示:
{ type: Show ,
id: 123,
title:名称,
description:有趣,
channelTitle: ifood.tv ,
lastUpdateTimestamp: 2014-04-20T20:34:59,
numOfVideos: 15}
如何格式化输出格式?
解决方案
尝试执行此操作:
卷曲... | json_pp
或带有和 bash :
卷曲... |节点<<< var o = $(cat); console.log(JSON.stringify(o,null,4));
检查 https://stedolan.github.io/jq/
In my Unix shell script, when I execute a curl command, the result will be displayed as below which I am redirecting to file:
{"type":"Show","id":"123","title":"name","description":"Funny","channelTitle":"ifood.tv","lastUpdateTimestamp":"2014-04-20T20:34:59","numOfVideos":"15"}
But, I want this output to put in the readable JSON format like below in the file:
{"type":"Show",
"id":"123",
"title":"name",
"description":"Funny",
"channelTitle":"ifood.tv",
"lastUpdateTimestamp":"2014-04-20T20:34:59",
"numOfVideos":"15"}
How do I format the output this way?
解决方案
Try doing this :
curl ... | json_pp
or with jq using the identity filter :
curl ... | jq '.'
curl ... | node <<< "var o = $(cat); console.log(JSON.stringify(o, null, 4));"
Check https://stedolan.github.io/jq/
这篇关于在Unix Shell脚本中以可读JSON格式显示curl输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文