开发者

JSON command line formatter tool for Linux [closed]

开发者 https://www.devze.com 2023-02-15 13:40 出处:网络
Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question?开发者_开发知识库 Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question?开发者_开发知识库 Update the question so it's on-topic for Stack Overflow.

Closed 9 years ago.

Improve this question

Is 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
0

精彩评论

暂无评论...
验证码 换一张
取 消