Result
JSONPath syntax
| Expression | What it selects |
|---|---|
$ | The whole document |
$.result.healthy | A key inside a key |
$['result']['block_height'] | The same with brackets, needed for keys with spaces or dots |
$.result.peers[0] | The first item of an array |
$.result.peers[-1:] | The last item |
$.result.peers[*].id | A key in every item |
$..latency_ms | A key at any depth |
$.result.peers[?(@.latency_ms > 20)] | Items that match a condition |
The tester runs JSONPath Plus in your browser. Nothing you paste is sent anywhere.
JSONPath examples
- Is the service healthy?
$.result.healthyreturnstrueorfalse. - Every peer id:
$.result.peers[*].idreturns["node-a", "node-b"]. - Slow peers only:
$.result.peers[?(@.latency_ms > 20)].idreturns["node-b"]. - All latencies wherever they are:
$..latency_msreturns[12, 48].
Use the path in an API monitor
A 200 status only means the server answered. Plenty of broken APIs return 200 with "healthy": false or a block height that stopped moving. failover.io HTTP monitors read the JSON body and check a value: it exists, equals, doesn't equal, contains or is greater or less than a number. If the check fails, the monitor is down even with a 200.
Monitors take simple paths: keys separated by dots and array indexes in brackets, written without the leading $.. So $.result.peers[0].id becomes result.peers[0].id. Wildcards, .. and filters select several values, so they don't work in a monitor. Under every result, the tester says whether your path works in a monitor and how to write it.
For blockchain nodes, the path you want is usually the block height or slot number. See how to monitor a JSON-RPC or blockchain node.
Related tools
- Cron expression tester: when the scheduled job behind that API runs next.
- Uptime calculator: what an uptime target allows in downtime.
Frequently asked questions
What is JSONPath?
A way to select values from a JSON document, the way XPath does for XML. An expression starts with $ for the root, then names keys and array indexes, like $.store.book[0].title.
How do I test a JSONPath expression?
Paste the JSON and the expression into the tester above. It shows every match and its type as you type, in your browser.
What is the difference between $.key and $..key?
One dot selects the key directly under the current level. Two dots search every level, so $..id returns every id anywhere in the document.
Can I use JSONPath in a failover.io monitor?
Monitors use the simple form: keys and [n] indexes without the leading $., like result.peers[0].id. The tester converts it for you when it can.