Skip to content

jclulow/jsondiff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

jsondiff

This is a first cut of a simple JSON diff utility, inspired by the usefulness and simplicity of trentm/json.

Usage

Install node.js, then simply call the script on two JSON files, like so:

jsondiff left.json right.json

License

ISC. See the header in the source.

Examples

Array Diff

Left:

[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]

Right:

[1,2,6,7,8,9,10,11,12,13,14,15,16,17,18,5,5,5,19,20]

Diff:

[
   1,
   2,
-  3,
-  4,
-  5,
   6,
   7,
   8,
   9,
   10,
   11,
   12,
   13,
   14,
   15,
   16,
   17,
   18,
+  5,
+  5,
+  5,
   19,
   20
]

Object Diff

Left:

{
  "c": 6,
  "aa": 7,
  "y": "diff all the things!",
  "z": true,
  "removed": {
    "red": true,
    "green": false,
    "blue": false
  },
  "common": {
    "john": 4,
    "still here": true
  },
  "equal": "!!!!",
  "wasarray": [ 1, 2 ,3 ,4],
  "stillisarray": [ 1, 1, 2, 5, 3, 4, 0, 2, 3, 2, 3, 5, 9]
}

Right:

{
  "y": "DIFF ALL THE THINGS!",
  "c": null,
  "aa": 5,
  "b": false,
  "z": true,
  "e": {
    "john": 5,
    "mary": 6,
    "stephen": 8
  },
  "common": {
    "john": null,
    "mary": 5,
    "still here": true
  },
  "equal": "!!!!",
  "wasarray": { "test": "5" },
  "stillisarray": [ 3, 4, 0, 2, 3, 4, 6, 4, 2, 3, 5, 9]
}

Diff:

{
-  aa: 7,
+  aa: 5,
+  b: false,
-  c: 6,
+  c: null,
   common: {
-    john: 4,
+    john: null,
+    mary: 5,
     still here: true
   },
+  e: {
+    john: 5,
+    mary: 6,
+    stephen: 8
+  },
   equal: "!!!!",
-  removed: {
-    blue: false,
-    green: false,
-    red: true
-  },
   stillisarray: [
-    1,
-    1,
-    2,
-    5,
     3,
     4,
     0,
     2,
     3,
+    4,
+    6,
+    4,
     2,
     3,
     5,
     9
   ],
-  wasarray: [
-    1,
-    2,
-    3,
-    4
-  ],
+  wasarray: {
+    test: "5"
+  },
-  y: "diff all the things!",
+  y: "DIFF ALL THE THINGS!",
   z: true
}

About

A simple command-line JSON diff utility

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published