Forum Discussion

lzc's avatar
lzc
Occasional Contributor
10 years ago

validating that 2 json nodes are equal

Hi,

we have the need to validate that 2 json nodes containing a batchid are equal. see attachment

 

this would seem to be very simple but yet we cannot get this to work properly.

 

i have tried this in an assertion and in a groovy script and both produce errors

 

def a = ($.points[0].batchId)
def b = ($.points[1].batchId)


assert a==b

i have tried a couple of other types of assertions to validate they are equal, with no luck.

 

isn't there an easy way to validate that 2 things are equal?

thanks Lee

 

 

 

  • Not a 100% sure whether I understood your question. But try this..

    Can't see the full json path from your screenshot, so make sure you mention the full json path including the root node name in below variable assignments( example : def a = json.root_node.next_node.next_to_next_node )

     

     

    import groovy.json.JsonSlurper

     

    def json = new JsonSlurper().parseText(messageExchange.responseContent)
    def a = json.points[0].batchId
    def b = json.points[1].batchId

    assert a == b

     

    Good Luck!

     

    Regards,

    Gilu Gopi

     

  • Not a 100% sure whether I understood your question. But try this..

    Can't see the full json path from your screenshot, so make sure you mention the full json path including the root node name in below variable assignments( example : def a = json.root_node.next_node.next_to_next_node )

     

     

    import groovy.json.JsonSlurper

     

    def json = new JsonSlurper().parseText(messageExchange.responseContent)
    def a = json.points[0].batchId
    def b = json.points[1].batchId

    assert a == b

     

    Good Luck!

     

    Regards,

    Gilu Gopi

     

    • lzc's avatar
      lzc
      Occasional Contributor

      yes, that works!

       

      thanks much

       

      Lee