Want to improve this question?开发者_开发知识库 Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this questionIs there an editor or tool for Linux command line to format JSON data?
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/
jq is a lightweight and flexible command-line JSON processor.
http://stedolan.github.io/jq/
jq is like sed for JSON data – you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.
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.
On Ubuntu jsonlint is provided by apt:python3-demjson
Usage:
$ sudo apt install -y python3-demjson
$ jsonlint -f input.json > output.json
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
精彩评论