Forum Discussion

siddhantoza29's avatar
siddhantoza29
New Contributor
2 years ago

Compare 2 JSON files in VBScript language using test complete

I want to compare 2 JSON files kept at different locations in C drive. The code should be such that it should compare all keys and values in the 2 JSONs and throw result.

    • siddhantoza29's avatar
      siddhantoza29
      New Contributor

      Hi, could you please share the code with me? I want to compare two large json files which also has a dynamic value which is the machine IP. This will keep changing as per the CDM deployments. So could you please suggest as to how to handle such json files using testcomplete and VBs. Aslo, if you could share a code for reference?

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        'Comparison' might mean different expected results that you did not mention...

        Plain file comparison will indicate whether or not files match as text or binary ones.

        You may use, for example, regular expressions (supported by VBScript) to replace irrelevant dynamic data with generic placeholders (for example, replace all ip addresses with '<ip>' string) and then compare files as text ones.

        VBScript does not support JSONs. If you really need to work with JSON, you may consider script extension created using JScript which supports work with JSON and call this extension from your VBScript test code (see help for more info on script extensions in TestComplete).

         

  • Thanks AlexKaras  
    rraghvani As you suggested it is possible to compare JSONs with Compare Files Operation. I want to compare two large json files which also has a dynamic value which is the machine IP. This will keep changing as per the CDM deployments. So could you please suggest as to how to handle such json files using testcomplete and VBs. Aslo, if you could share a code for reference?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I'm hoping that you have read the contents of the link that I had provided, as it mentions the methods to use. Within the documentation, there are references to code examples.