Ask a Question

How I can use JSON Path assertion for two different strings without using Groovy


How I can use JSON Path assertion for two different strings without using Groovy

I have a JSON Path assertion which expecting a string like "PAYMENT REVERSED" but sometimes the string also can be "PAYMENT REVERSAL". Is it possible to do as follows? (tried but didn't work) or what is the best way to do this? 



I tried the JSONPath Regx match assertion as well but didn't work. Help much appreciated. 



Champion Level 3

You could try using regex.

For more details:


@nmrao , thanks for the reply. Can you please explain more how to get the regular expression for two strings? 

Champion Level 3

The samples are available in the link given in the previous reply. Have you gone through it?

Community Hero

Hi @mpw83 


I understand a reluctance relying on coding if you're not a coder (or if managers dont want to include code when considering future maintenance, etc.) - but adding a small 2 line script assertion would resolve this problem.


Also - considering that the two possiible values are PAYMENT REVERSED and PAYMENT REVERSAL, wouldnt they have identical regex patterns anyway?


a while back I had to assert that a certain json value had either of 2 values and @nmrao  supplied me the following Script Assertion:

//courtesy of Rao
def jsonResponseContent = new groovy.json.JsonSlurper().parseText(context.response) assert jsonResponseContent.parentattribute.childattribute == ['PAYMENT REVERSED' || 'PAYMENT REVERSAL']

As I say - I know you say you dont want to use groovy script - but it's a two line script assertion - anyone reading this (even with zero groovy) would be able to understand what the code is actually doing.


If you're still struggling with the JSON Regex match assertion - perhaps the above might help you?


Just a suggestion, cheers,




if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

@richie , thanks for the reply. yes .. I was able to solve this issue using groovy but want to know how I can directly use via the UI.. Thanks 

yes I had but didn't work. Because of the way that I am getting the data. Thanks anyway.  

Showing results for 
Search instead for 
Did you mean: