美文网首页
json文件格式化工具

json文件格式化工具

作者: testerzhang | 来源:发表于2020-05-31 16:55 被阅读0次

    前言

    有时候获取到的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 自带的,是没有高亮的效果

    对比图

    相关文章

      网友评论

          本文标题:json文件格式化工具

          本文链接:https://www.haomeiwen.com/subject/trkrzhtx.html