Is there an editor or tool for Linux command line to format JSON data?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
alias pp='python -mjson.tool' pp mydata.json
From the first link in the accepted answer: http://ruslanspivak.com/2010/10/12/pretty-print-json-from-the-command-line/
回答2:
jq is a lightweight and flexible command-line JSON processor.
jq is written in portable C, and it has zero runtime dependencies. You can download a single binary, scp it to a far away machine, and expect it to work.
回答3:
On Ubuntu jsonlint is provided by apt:python-demjson
Usage:
$ sudo apt-get install python-demjson $ jsonlint -f input.json > output.json
回答4:
Add to vimrc:
" Format JSON data map <C-F6> :%!python -m json.tool<CR>
And you can use the shortcut CTRL+F6 to format json data
Or just under vim's command mode:
%!python -m json.tool