Avatar of the_7th_king
the_7th_king
Flag 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!
jQueryJavaScriptASP.NET

Avatar of undefined
Last Comment
the_7th_king

8/22/2022 - Mon
Jon Norman

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.
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
Jon Norman

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
the_7th_king

ASKER
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!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
the_7th_king

ASKER
doing it with using objects seems like the best way to me
thanks for the GREAT help!