jsonpathsite24x7

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


Solution

  • 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