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:[{ "name":"value1", "position":0 },{ "name":"value2", "position":0 }]
The JSON is invalid because we expect the value of "position" to be different for each node.
How do we write an assertion for this that does not require the usage of groovy? In XPath Expressions we can use additional logic like the following (not a valid XPath, just an example)
//Results[1]/ResultSet[1]/Row[1]/nodes[1].position != //Results[1]/ResultSet[1]/Row[1]/nodes[2].position
Is there a related functionality for JSONPaths or other alternatives that allow you to use a negative-match?
(I would like solutions outside of groovy-scripting, either in the expected value or as its own step, I am fully aware that those would be the simplest solutions)
Thanks in advance for any help provided
pb1
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