This is a question that involves a more complicated way of comparing. So this is not a duplicate
I created JqTree that when a user changes their tree structure, both "old" JSON
and "new" JSON
structures should be compared, and only JSON
values that have been changed should be displayed.
For instance:
[{"name":"node1","id":1,"is_open":true,"children": [ {"name":"child1","id":2}, {"name":"child2","id":3} ] }]
![Example](https://fooobar.com//img/5108d01514119b6853a95e5bfbe84666.png)
After the client placed child1
under child2
[{"name":"node1","id":1,"is_open":true,"children": [ {"name":"child2","id":3}, {"name":"child1","id":2} ] }]
![example](https://fooobar.com//img/7af6099be20241d83cb6b3d748d8d72f.png)
I just would like to compare them and check what values have been changed, and show them with alert
, which in this case will be:
{"name": "Child2", "ID": 3},
{"Name": "child1", "identifier": 2}
So far I have this tiny code that compares them:
JSON.stringify (object1) === JSON.stringify (object2); // I know that it is not too reliable.
But I'm looking for something that checks for "difference" and extracts it from JSON.
Thanks in advance.