#json #semantic #cli #difference #outputs #sorting #array

bin+lib jsondiff

A tool for outputs semantic difference of json

1 unstable release

0.1.0 Sep 12, 2021

#2009 in Development tools

Download history 8/week @ 2024-07-22 14/week @ 2024-07-29 8/week @ 2024-08-12 23/week @ 2024-08-19 25/week @ 2024-08-26 13/week @ 2024-09-02 4/week @ 2024-09-09 33/week @ 2024-09-23 36/week @ 2024-09-30 62/week @ 2024-10-07 30/week @ 2024-10-14 4/week @ 2024-10-21 24/week @ 2024-10-28

120 downloads per month

MIT license

14KB
243 lines

jsondiff

A tool for outputs semantic difference of json.
"semantic" means:

  • sort object key before comparison
  • sort array before comparison (optional, but currently can not be disabled)

Installation

$ cargo install jsondiff

Usage

test1.json

{
  "b": "bv",
  "arr": [1,2,3],
  "arr2": [
    {"a":  "av", "obj": {"arr": [1,2,3], "z":  "zv"}},
    {"b":  "bv", "obj": {"arr": [2,3,1], "z":  "zv"}},
    {"c":  "cv", "obj": {"arr": [3,2,1], "z":  "zv"}}
  ]
}

test2.json

{
  "b": "bv",
  "arr": [1,3,2],
  "arr2": [
    {"c":  "cv", "obj": {"arr": [2,3,1], "z":  "zv"}},
    {"b":  "bv", "obj": {"arr": [1,2,3], "z":  "zv"}},
    {"a":  "av", "obj": {"arr": [3,2,1], "z":  "zv"}}
  ]
}

test3.json

{
  "b": "bv",
  "arr": [3,2,1],
  "arr2": [
    {"c":  "cv", "obj": {"arr": [1,2,3], "z":  "zv"}},
    {"b":  "bv", "obj": {"arr": [2,3,1], "z":  "zv"}},
    {"a":  "av", "obj": {"arr": [3,2,1,4], "z":  "zv"}}
  ]
}
$ jsondiff test1.json test2.json
// => no output (no difference)

$ jsondiff test1.json test3.json
10:           "arr": [
11:             1,
12:             2,
13: -           3
13: +           3,
13: +           4
14:           ],
15:           "z": "zv"
16:         }
----

options

$ jsondiff --help
jsondiff 0.1.0
A tool for outputs semantic difference of json

USAGE:
    jsondiff [FLAGS] [OPTIONS] <file-path1> <file-path2>

FLAGS:
    -h, --help                      Prints help information
    -n, --output-normalized-json    Outputs normalized json as "normalized1.json" and "normalized2.json"
    -V, --version                   Prints version information

OPTIONS:
    -U <unified>        Generate diffs with <n> lines of context [default: 3]

ARGS:
    <file-path1>    
    <file-path2>   

Dependencies

~4–15MB
~134K SLoC