Service Virtualization

 View Only
  • 1.  Compare two JSON responses with dynamic values

    Posted Sep 19, 2019 01:55 AM
    Hi, 
    Is there a way to compare two JSON responses in DevTest v10.3
    I need to verify all nodes are returned in the response but would like to ignore few node values that change dynamically.
    Something similar to XML side by side compare assertion?

    ------------------------------
    Many Thanks
    Leela
    ------------------------------


  • 2.  RE: Compare two JSON responses with dynamic values

    Posted Sep 26, 2019 02:01 AM
    Hi Leela,

    I don't think there is any such utility available in DevTest for JSON. However, if you have small JSON, you can try using filters or for full comparison, you can use Ensure properties are equal assertions.

    Thanks

    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------



  • 3.  RE: Compare two JSON responses with dynamic values

    Posted Sep 26, 2019 03:27 AM
    Hi All,

    We can use "Ensure Result Equals" Assertion and in the JSON path  u can pass the node/ attribute that u want to verify.
    {{JSONPath}}
    eg:
    $
    $.response.segments[0].fares[0]
    ....
    Ensure Result Equals


    Thanks & Best Regards,
    Rohit Sawant



  • 4.  RE: Compare two JSON responses with dynamic values
    Best Answer

    Broadcom Employee
    Posted Sep 26, 2019 07:01 AM
    You can use "Graphical XML diff "assertion and select text option. You can also ignore nodes in XML but I didn't try on JSON.

    https://techdocs.broadcom.com/content/broadcom/techdocs/us/en/ca-enterprise-software/continuous-testing/devtest-solutions/10-5/graphical-xml-side-by-side-comparison0.html

    Prema


  • 5.  RE: Compare two JSON responses with dynamic values

    Posted Sep 26, 2019 10:27 AM
      |   view attached
    I usually use Ensure Result equals to compare 2 jsons. If you want to ignore certain fields in comparison. you need to use "JSON Ignored Nodes companion" where you can pass the json path and it will be ignored in the comparison. Attaching the screenshot of assertion.

    ------------------------------
    SOA Tester
    Kroger
    OH
    ------------------------------



  • 6.  RE: Compare two JSON responses with dynamic values

    Posted Sep 26, 2019 07:59 PM
    Hi All, Thanks for your response.
    @Tushar Ranjan :Hope you are doing good.
    Yep tried that option earlier, but this companion ignores the node as well. I just need to ignore the text value in the node.​
    Currently i convert the JSON reponse to XML and then do an XML compare. But looking for a better option, if any.


  • 7.  RE: Compare two JSON responses with dynamic values

    Posted Sep 27, 2019 01:43 AM
    Hi Leela,

    I was about to suggest this :)

    How you are converting the JSON to XML now - I have done it using JSON object.

    Thanks.

    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------



  • 8.  RE: Compare two JSON responses with dynamic values

    Posted Oct 02, 2019 09:29 AM
    I think you can give the property as below.

    $[*].properties[?(@.propertyName==flag)].newValue

    ------------------------------
    SOA Tester
    Kroger
    OH
    ------------------------------