What is the correct way to compare jsonPath's value as an integer

Hi, I would like to perform a simple check that verifies that the JSON response contains an integer that is greater than 0.
I’ve seen numerous examples that do string checks but nothing using integers.

How do I do something like this:
check(status.is(200), jsonPath("$.hits.total").asInstanceOf[Int] > 0)

Thanks.

Like this?

jsonPath("$.hits.total > 0")

http://jsonpath.herokuapp.com/?path=%24.store.book%5B?(@.price%20%3C%2010)%5D

Oh, I didn’t realize that we were supposed to assert inside the expression. Having this somewhere in the docs right along with the HTTP status check would be very useful to first timers.

Thanks!

Asserting in the expression is not mandatory, as this works too :

jsonPath("$.hits.total").ofType[Int].greaterThan(5)

Hi Pierre - hoping that this thread is not too stale…

I have a similar requirement (needing to check prometheus metrics during the test) and I’ve tried this approach, but I’m getting the response:

16:13:07.867 [gatling-http-thread-1-2] WARN i.gatling.http.ahc.ResponseProcessor - Request ‘get prometheus metric - systemload_average’ failed: jsonPath($…value[1]).find.greaterThan(0.0), but actually can’t compare nothing and 0.0
1.67

My request looks like this (developing in Intellij):

ive noticed a similar issue and in one of those cases i had luck putting a asterisk wildard on my locator string. not ideal but it got me unblocked.

Thanks for the quick response Jon!

Sorry but my json path abilities are not great - how do I use the asterisk in this request?

what I mean is, instead of “$…field[0]” you could try “$….field[0]" . Or be more specific like "$.whatever..field[0]” . This is probably really inefficient but if it works for you , it might give you more information on your locator problem and it might get you unblocked.

Thanks Jon. Much appreciated. I’ll let you know how I get on…

Please properly read Pierre’s sample: you’re missing his «ofType[Int] » so you’re converting to String.