0

Compare two JSON Objects and validate if data mismatched using jQuery. I need to select records in two tables and compare selected column(firstName) values are same only will allow for further validations. If firstname is mismatched have to show alert like data is mismatched. I tried with below code, please suggest me the issue..

    const obj1Keys = Object.keys(jsonData1);
    const obj1Values = Object.values(jsonData1);
    const obj2Keys = Object.keys(jsonData2);
    const obj2Values = Object.values(jsonData2);

    for (let i = 0; i < obj1Keys.length; i++) {
      for (let j = 0; j < obj2Keys.length; j++) {
        if (obj1Keys[i] === obj2Keys[j]) {
          if (obj1Values[2] !== obj2Values[2]) {
            alert("data mismatched");
          }
        }
      }
    }
  }

Eg: firstTable : Toto and second table Toto, Toto >> allowed. If any mismatched have to show alert.

Have to validate 1 to many and many to 1.

Stackblitz

Rajasekhar
  • 2,215
  • 3
  • 23
  • 38
  • This is referance value in example both base value person so there will be no differance between tables . – mr. pc_coder Jan 05 '21 at 10:06
  • Does this answer your question? [How to compare two JSON have the same properties without order?](https://stackoverflow.com/questions/26049303/how-to-compare-two-json-have-the-same-properties-without-order) – Girish Jan 05 '21 at 12:31

0 Answers0