Ask a Question

JsonPath RegEx Match

jjaspe
New Contributor

JsonPath RegEx Match

I'm trying to assert that an JSON HttpResponse has the following string in it :

"TotalNumberOfResults": 1

but the one could be any number except 0.

I tried using JsonPath RegEx Match but when I type in the Regex it doesn't get saved, so it always passes. 

I also tried doing a regular Contains assertion, with this Regex

"TotalNumberOfResults": [1-9]\d* 

and that didn't work either. I know the expression is right because i tried it on RegExr.com with the exact output of the HTTP response and it gets a match. 

I also tried doing a JsonPath Match assertion with $['TotalNumberOfResults']>0 in the expression and "true" in the expected result, didn't work either.

 

Any help would be appreciated. Thanks in advance.

6 REPLIES 6
PaulMS
Super Contributor

The first option using JsonPath RegEx Match should work.

Can you try recreating the assertion to see if it saves correctly?

 

I have used a similar assertion

JSONPath Expression  $.Total

Regular Expression  ^[1-9][0-9]*$

Expected Result  true

HKosova
SmartBear Alumni (Retired)

For "greater than" checks, use the XPath Match assertion:


XPath assertion: //*:TotalNumberOfResults > 0

Expected result: true


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
jjaspe
New Contributor

Yes I tried many times in different test cases and it never saves the expression. Anyway, I learned how to use script assertions with jsonSlurper so I'm doing everything JSON related that way now. Thanks.

PaulMS
Super Contributor

That is probably a defect with saving a regular expression in the assertion.

I actually created JSONPath RegEx Match assertion in SoapUI open source version with no problem, but the regular expression is not saved in Ready API.

edweerdt
Contributor

I am having the same problem of not being able to save changes to an existing JSONPath RegEx Match Assertion or a newly created one.

 

Did anyone report this as a bug?

pedro
Occasional Contributor

I found this post where version 1.9 has a bug and it does not save the RegEx.

 

https://community.smartbear.com/t5/SoapUI-NG/Bug-Cannot-save-a-regex-statement-for-JSONPath-RegEx-Ma...

 

please read the latest post on that thread.

 

Regards

cancel
Showing results for 
Search instead for 
Did you mean: