Forum Discussion

pb1's avatar
pb1
Contributor
6 years ago

JSONPath - negative match alternatives

Hi there.   We are currently trying to assert, that two sibling nodes in a JSON do not have the same value in one of their parameters. For example for the parameter position:   nodes:[{ "na...
  • richie's avatar
    6 years ago

    Hi pb1 

     

    I don't think there is a native functionality option.  I asked this question about 6 months ago - but the 3 XPATH/XML options I'm aware of didnt work for JSONPATH/JSON.

     

    The only answer I found was to use groovy (which Rao kindly put together for me). 

     

    If someone does come back with a non-groovy answer - great! I'd welcome knowing the option - but for now when I have to do this when the response type is json - I rely on groovy.

     

    I have one other suggestion that 'might' help you get around this that's just popped in my head - so never tried it myself.  Depending on your webservice (for this particular test step which returns json) you could add an Accept header (value = application/xml) - to force the response content type to XML.  Perhaps you could use one of the XML related options using this approach?  I appreciate it wouldn't be the first option you might consider - but if you're really adamant you dont want to try groovy - switching the content to XML for this single test might allow you to get around this?

     

    Hope this helps!......although I suspect it didn't!

     

    Cheers,

     

    rich