andreyvit/json-diff

Comparing differences in inner objects not show the difference

Closed this issue · 1 comments

While comparing:
{
"eventId": "PaymentMethodMigrationCreateNotification_25",
"event": {
"paymentMethod": {
"id": "PaymentMethod_3649901670902106",
"details": {
"accountNumberType": "other",
"accountType": "other",
"accountNumber": "ES7621030722890030024676"
},
"lastModifiedOn": "2020-07-17T14:23:09.000Z"
}
}
}

with

{
"eventId": "PaymentMethodMigrationCreateNotification_25",
"event": {
"paymentMethod": {
"id": "PaymentMethod_3649901670902106",
"name": "test",
"details": {
"accountNumberType": "other",
"accountNumber": "ES7621030722890030024676"
},
"lastModifiedOn": "2020-07-17T14:23:09.000Z"
}
}
}

It just shows the the object details as if it have changed (but doesn't shows the change):

{
event: { paymentMethod: { name__added: 'test', details: [Object] } }
}

The code is:
var jsonDiff = require('json-diff');
var fs = require('fs');

var f1 = fs.readFileSync("v1.json",'utf8');
var f2 = fs.readFileSync("v2.json",'utf8');

var j1 =JSON.parse(f1);
var j2 =JSON.parse(f2);

console.log(jsonDiff.diff(j1, j2, {keysOnly: true}));

This works properly in version 0.6.0:

$ cat v1.json
{
   "event" : {
      "paymentMethod" : {
         "details" : {
            "accountNumber" : "ES7621030722890030024676",
            "accountNumberType" : "other",
            "accountType" : "other"
         },
         "id" : "PaymentMethod_3649901670902106",
         "lastModifiedOn" : "2020-07-17T14:23:09.000Z"
      }
   },
   "eventId" : "PaymentMethodMigrationCreateNotification_25"
}
$ cat v2.json
{
   "event" : {
      "paymentMethod" : {
         "details" : {
            "accountNumber" : "ES7621030722890030024676",
            "accountNumberType" : "other"
         },
         "id" : "PaymentMethod_3649901670902106",
         "lastModifiedOn" : "2020-07-17T14:23:09.000Z",
         "name" : "test"
      }
   },
   "eventId" : "PaymentMethodMigrationCreateNotification_25"
}
$ json-diff v1.json v2.json
 {
   event: {
     paymentMethod: {
+      name: "test"
       details: {
-        accountType: "other"
       }
     }
   }
 }
$ json-diff --full v1.json v2.json
 {
   event: {
     paymentMethod: {
+      name: "test"
       details: {
-        accountType: "other"
         accountNumber: "ES7621030722890030024676"
         accountNumberType: "other"
       }
       id: "PaymentMethod_3649901670902106"
       lastModifiedOn: "2020-07-17T14:23:09.000Z"
     }
   }
   eventId: "PaymentMethodMigrationCreateNotification_25"
 }