json文件格式化工具

前言

有时候获取到的json文件没有经过格式化,可以安装一个格式化工具进行格式化。

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

帮助说明

$ ./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": "成功"
}

这里是会有高亮的效果,如果你用python 自带的,是没有高亮的效果

对比图
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

相关阅读更多精彩内容

友情链接更多精彩内容