json文件格式化工具

前言

有時(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ì)比圖
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請(qǐng)通過(guò)簡(jiǎn)信或評(píng)論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容