4 Replies Latest reply on Jun 11, 2019 3:11 AM by anba89

    vRO - compare two complex JSON

    anba89 Novice

      I need to compare two complex JSON Body with vRO.

      Does anyone have any idea how I can do this?

      It's about comparing two NSX DFW configurations. So XML would work, too, if it's easier to compare.

        • 1. Re: vRO - compare two complex JSON
          daphnissov Guru
          vExpertCommunity Warriors

          Probably best asked in the vRO sub-forum.

          • 2. Re: vRO - compare two complex JSON
            anba89 Novice

            Thanks. I moved it to the vRO sub-forum.

            • 3. Re: vRO - compare two complex JSON
              eoinbyrne Hot Shot

              When you say compare do you really mean diff as you might in Unix?

               

              Or are you simply interested in checking if the two objects are equal? If the latter then this is will give a simple true/false

               

              if(JSON.stringify(obj1) == JSON.stringify(obj2))

               

              There are a few notes on this too

              1.  Purists might argue that the test there should be "==="

              2.  The simple comparison here will only return true if all the internal fields are in the same order (it's comparing text after all)

              3.  Converting objects to string like this can be expensive if the objects are large

               

              If you want to be able to compare objects regardless of internal field ordering then you might look at Lodash - it's a free JS module built for Websites and Node.js projects but you *should* be able to load it into a vRO context and use it's functionality. Or, copy out the relevant bits to a script/action in vRO and get your comparison done

               

              If you want a full diff and report then you would have to code a specific parser / inspector function I'd imagine. Your XML suggestion might work too but you'd be also writing code for that

              • 4. Re: vRO - compare two complex JSON
                anba89 Novice

                Thank you very much for your feedback.

                With compare I mean a diff to get all the differences and not only a true or false.

                I will check Lodash and I'll get back to you.