Link to home
Start Free TrialLog in
Avatar of the_7th_king
the_7th_kingFlag for India

asked on

Adding deep search in JSON diff

Hello,

This link provides an excellent JSON diff algorithm. : http://tlrobinson.net/projects/javascript-fun/jsondiff/
However, what it does not do is provide for deep search of element nodes.

Any idea how do we do this?

Thanks!
Avatar of Jon Norman
Jon Norman
Flag of United Kingdom of Great Britain and Northern Ireland image

do you have an example of where it is not working?

it seems to be coded to go down each node until it gets to the end.
Avatar of the_7th_king

ASKER

JSON1:

[
   {
      "id":"210",
        "fees":"5000",
        "annualpayment":"9000",
        "memberlist":
      [
         {
            "memberid":"210O42597",
            "chairmanflag":"on",
            "meeting":"75",
            "exception":"0"
         },
         {
            "memberid":"210O80245",
            "chairmanflag":"on",
            "meeting":"75",
            "exception":"0"
         },
         {
            "memberid":"210O106573",
            "chairmanflag":"on",
            "meeting":"75",
            "exception":"0"
         }
      ]
   }
]


JSON2:

[
   {
      "id":"210",
        "fees":"5000",
        "annualpayment":"9000",
        "memberlist":
      [
         {
            "memberid":"210O106573",
            "chairmanflag":"on",
            "meeting":"75",
            "exception":"0"
         },
         {
            "memberid":"210O42597",
            "chairmanflag":"on",
            "meeting":"75",
            "exception":"0"
         },
         {
            "memberid":"210O80245",
            "chairmanflag":"on",
            "meeting":"75",
            "exception":"0"
         }
      ]
   }
]


The above 2 should compute as equal... which they do not as it compares the first node of first json with the first node of the second json... even though it should look through all the nodes.
ASKER CERTIFIED SOLUTION
Avatar of Jon Norman
Jon Norman
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Very interesting explanation, JonNorman

I understand what that you're saying that it's pretty complicated to do the treecompare on the JSON itself and doing it after converting to objects might be simpler.

Can you elaborate on how would I do this kind of comparision if I converted the JSON strings to objects?

Many thanks!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
doing it with using objects seems like the best way to me
thanks for the GREAT help!