如何从命令行漂亮地打印JSON文件? [英] How can I pretty-print a JSON file from the command line?
本文介绍了如何从命令行漂亮地打印JSON文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含JSON元素序列的文件:
I've a file with a sequence of JSON element:
{ element0: "lorem", value0: "ipsum" }
{ element1: "lorem", value0: "ipsum" }
...
{ elementN: "lorem", value0: "ipsum" }
是否有一个Shell脚本来格式化JSON以以可读形式显示文件内容?
Is there a shell script to format JSON to display file content in a readable form?
我看过此发布,我认为这是一个很好的起点!
I've seen this post, and I think is a good starting point!
我的想法是迭代文件中的行,然后:
My idea is to iterate rows in the file and then:
while read row; do echo ${row} | python -mjson.tool; done < "file_name"
还有其他想法吗?
推荐答案
将文件中的结果放入python json工具2.6及以后版本
Pipe the results from the file into the python json tool 2.6 onwards
cat 'file_name' | python -m json.tool
这篇关于如何从命令行漂亮地打印JSON文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文