Skip to content

A JSON diff utility

License

Notifications You must be signed in to change notification settings

yazgazan/jaydiff

Repository files navigation

JayDiff

Go Report Card GoDoc Build Status Coverage Status Maintainability

A JSON diff utility.

Install

Downloading the compiled binary

  • Download the latest version of the binary: releases
  • extract the archive and place the jaydiff binary in your $PATH

From source

  • Have go 1.11 or greater installed: golang.org
  • run go get -u github.com/yazgazan/jaydiff

Usage

Usage:
  jaydiff [OPTIONS] FILE_1 FILE_2

Application Options:
  -i, --ignore=               paths to ignore (glob)
      --indent=               indent string (default: "\t")
  -t, --show-types            show types
      --json                  json-style output
      --ignore-excess         ignore excess keys and array elements
      --ignore-values         ignore scalar's values (only type is compared)
  -r, --report                output report format
      --slice-myers           use myers algorithm for slices
      --stream                treat FILE_1 and FILE_2 as JSON streams
      --stream-lines          read JSON stream line by line (expecting 1 JSON value per line)
      --stream-ignore-excess  ignore excess values in JSON stream
      --stream-validate       compare FILE_2 JSON stream against FILE_1 single value
  -v, --version               print release version

Help Options:
  -h, --help                  Show this help message

Examples

Getting a full diff of two json files:

$ jaydiff --show-types old.json new.json

 map[string]interface {} map[
     a: float64 42
     b: []interface {} [
         float64 1
-        float64 3
+        float64 5
+        float64 4
     ]
     c: map[string]interface {} map[
-        a: string toto
+        a: string titi
-        b: float64 23
+        b: string 23
     ]
-    e: []interface {} []
-    f: float64 42
     g: []interface {} [1 2 3]
+    h: float64 42
 ]

Ignoring fields:

$ jaydiff --show-types \
    --ignore='.b\[\]' --ignore='.d' --ignore='.c.[ac]' \
      old.json new.json

 map[string]interface {} map[
     a: float64 42
     b: []interface {} [1 3]
     c: map[string]interface {} map[
-        b: float64 23
+        b: string 23
     ]
-    e: []interface {} []
-    f: float64 42
     g: []interface {} [1 2 3]
+    h: float64 42
 ]

Report format:

$ jaydiff --report --show-types old.json new.json

- .b[1]: float64 3
+ .b[1]: float64 5
+ .b[2]: float64 4
- .c.a: string toto
+ .c.a: string titi
- .c.b: float64 23
+ .c.b: string 23
- .e: []interface {} []
- .f: float64 42
+ .h: float64 42

JSON-like format:

$ jaydiff --json old.json new.json

 {
     "a": 42,
     "b": [
         1,
-        3,
+        5,
+        4
     ],
     "c": {
-        "a": "toto",
+        "a": "titi",
-        "b": 23,
+        "b": "23"
     },
-    "e": [],
-    "f": 42,
     "g": [1,2,3],
+    "h": 42
 }

Ignore Excess values (useful when checking for backward compatibility):

$ jaydiff --report --show-types --ignore-excess old.json new.json

- .b[1]: float64 3
+ .b[1]: float64 5
- .c.a: string toto
+ .c.a: string titi
- .c.b: float64 23
+ .c.b: string 23
- .e: []interface {} []
- .f: float64 42

Ignore values (type must still match):

$ jaydiff --report --show-types --ignore-excess --ignore-values old.json new.json

- .c.b: float64 23
+ .c.b: string 23
- .e: []interface {} []
- .f: float64 42

JSON streams:

$ jaydiff --stream --json old.json new.json

 [
      {"foo":"bar"},
     [
         2,
         3,
         4,
         {
+            "v": "some"
         }
     ],
+    {"some":"thing"}
 ]

Validating JSON stream types:

$ jaydiff --ignore-excess --ignore-values --stream-validate --report --show-types base.json stream.json

- [1].bar: float64 4.2
+ [1].bar: string !

Ideas

  • JayPatch

Sponsored by Datumprikker.nl