JSFiddle - React, Tailwind, and code Playground

by Per Ă…strand

JavaScript

var json1 = {"entityinfo":{"entity":"Customer29Jan16","tenantid":"292FEC76-5F1C-486F-85A5-09D88096F098","timestamp":"2015-12-15T10:16:06.322Z"},"collections":{"Customer29Jan16":{"rowset":[{"CuId":"123","Name":"Ranjini","Quantity":"60","Rate":"60","Amount":"3600"}],"meta":{"parentreference":"***","pkname":"***","fkname":"***"},"rowfilter":[]},"Customer29Jan16Obj":{"rowset":[{"CuObjId":"456","FullAddress":"Electronic City","ObjAddr":"Bangalore","ObjName":"Testing"}],"meta":{"parentreference":"***","pkname":"***","fkname":"***"},"rowfilter":[]}}};

var json2 = {"entityinfo":{"entity":"Customer29Jan16","tenantid":"292FEC76-5F1C-486F-85A5-09D88096F098","timestamp":"2015-12-15T10:16:06.322Z"},"collections":{"Customer29Jan16":{"rowset":[{"CuId":"123","Name":"Vijay","Quantity":"60","Rate":"60","Amount":"3600"}],"meta":{"parentreference":"***","pkname":"***","fkname":"***"},"rowfilter":[]},"Customer29Jan16Obj":{"rowset":[{"CuObjId":"456","FullAddress":"SilkBoard","ObjAddr":"Bangalore","ObjName":"Testing"}],"meta":{"parentreference":"***","pkname":"***","fkname":"***"},"rowfilter":[]}}};

function compareJSON(json1, json2) {
  var objectsDiffering = [];
  compareJSONRecursive(json1, json2, objectsDiffering);
  return objectsDiffering;
}

function compareJSONRecursive(json1, json2, objectsDiffering) {
	for(prop in json1) {
    if(json2.hasOwnProperty(prop)) {
    	switch(typeof(json1[prop])) {
      	case "object":
        	compareJSONRecursive(json1[prop], json2[prop], objectsDiffering);
          break;
        default:
        	if(json1[prop] !== json2[prop]) {
            objectsDiffering.push(json1);
          }
          break;
      }
    } else {
      objectsDiffering.push(json1);
      break;
    }
  }
}

var differing = compareJSON(json1, json2);
console.log(JSON.stringify(differing));