Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assert status via jsonpath

I would like to add a monitor to detect unhealthy service and sending alert in that case. I've expose a simple REST API - /healthy which returns a JSON e.g. {"healthy": true}.

Then I've added a REST API Monitor to my site24x7 account, set the content checks response format to JSON and now I should provide a JSONPath to be asserted.

In a JSONPath online tester when I use $.healthy I get [true]. But I guess I should try to assert that return value.

Using following expressions didn't worked

$.(@healthy=='true')
$.[?(@.healthy=='true')]
$[?(@.healthy=='true')]
$?(.healthy=='true')
$.healthy=='[true]'
$.healthy==[true]
$.healthy==['true']

Thought I should evaluate the assertion expression using () or filtering.

How I can assert the return healthy status?

In site24x7 example I see an example for JSONPath expression

$..[?(@.overallStatus=='true')]

which i couldn't make it work in my case

Thank you

like image 440
Ami Hollander Avatar asked Oct 19 '25 05:10

Ami Hollander


1 Answers

It's extraordinarily poorly documented but I looked at the examples for Jayway JsonPath and eventually found this worked:

$.[?(@.healthy == true)]

Since your struct is so basic I think this might work as well:

[?(@.healthy == true)]

You can try it out on https://www.site24x7.com/tools/json-path-evaluator.html

like image 146
parsley72 Avatar answered Oct 22 '25 04:10

parsley72



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!