前言
有時(shí)候獲取到的json文件沒(méi)有經(jīng)過(guò)格式化,可以安裝一個(gè)格式化工具進(jìn)行格式化。
jq是json文件處理以及格式化顯示,支持高亮,可以替換 python -m json.tool
下載
下載地址:https://github.com/stedolan/jq/releases
這里以下載1.6版本為例:
$ wget https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 -O jq
$ chmod +x jq
幫助說(shuō)明
$ ./jq
jq - commandline JSON processor [version 1.6]
Usage: ./jq [options] <jq filter> [file...]
./jq [options] --args <jq filter> [strings...]
./jq [options] --jsonargs <jq filter> [JSON_TEXTS...]
jq is a tool for processing JSON inputs, applying the given filter to
its JSON text inputs and producing the filter's results as JSON on
standard output.
The simplest filter is ., which copies jq's input to its output
unmodified (except for formatting, but note that IEEE754 is used
for number representation internally, with all that that implies).
For more advanced filters see the jq(1) manpage ("man jq")
and/or https://stedolan.github.io/jq
Example:
$ echo '{"foo": 0}' | jq .
{
"foo": 0
}
例子
$ cat 1.json
{"resultcode":200, "desc": "成功"}
$ cat 1.json |./jq
{
"resultcode": 200,
"desc": "成功"
}
這里是會(huì)有高亮的效果,如果你用python 自帶的,是沒(méi)有高亮的效果

對(duì)比圖