How can I completely sort arbitrary JSON using jq?

后端 未结 2 1545
忘了有多久
忘了有多久 2021-02-08 02:35

I want to diff two JSON text files. Unfortunately they\'re constructed in arbitrary order, so I get diffs when they\'re semantically identical. I\'d like to use jq (or whateve

2条回答
  •  旧时难觅i
    2021-02-08 02:50

    I want to diff two JSON text files.

    Use jd with the -set option:

    No output means no difference.

    $ jd -set A.json B.json
    

    Differences are shown as an @ path and + or -.

    $ jd -set A.json C.json
    
    @ ["People",{}]
    + "Carla"
    

    The output diffs can also be used as patch files with the -p option.

    $ jd -set -o patch A.json C.json; jd -set -p patch B.json
    
    {"City":"Boston","People":["John","Carla","Bryan"],"State":"MA"}
    

    https://github.com/josephburnett/jd#command-line-usage

提交回复
热议问题