Advanced API Monitoring with JSONPath
When monitoring APIs, sometimes checking the HTTP status code isn’t enough. You might need to verify that specific data is present in the response body or that values meet certain criteria. StatusPage.me supports JSONPath for deep inspection of JSON responses.
What is JSONPath?
JSONPath is a query language for JSON, similar to how XPath is used for XML. It allows you to select specific parts of a JSON structure using a path expression.
Using JSONPath in Monitors
When creating or editing an API Monitor:
- In the Advanced expected conditions section, verify you are checking a JSON response.
- Add a new condition row.
- Select JSON Path as the target.
- Enter your JSONPath expression in the path field (usually starting with
$.). - Choose an operator (e.g.,
equals,contains,matches). - Enter the expected value.
Syntax Basics
Our JSONPath implementation supports standard syntax:
$: The root object/element.or[]: Child operator*: Wildcardn:s: Array slice
Examples
Consider this JSON response from a payment API:
{
"status": "success",
"data": {
"balance": 500,
"currency": "USD",
"transactions": [
{ "id": 1, "state": "completed" },
{ "id": 2, "state": "pending" }
]
},
"maintenance": false
}
| Goal | JSONPath Expression | Expected Value | Condition |
|---|---|---|---|
| Check status | $.status | success | equals |
| Check balance | $.data.balance | 500 | gte |
| Check maintenance | $.maintenance | false | equals |
| first transaction state | $.data.transactions[0].state | completed | equals |
Troubleshooting
- Case Sensitivity: JSON keys and values are case-sensitive.
- Path Validity: Ensure your path starts with
$to reference the root. - Numbers vs Strings: When comparing numbers, ensure you select numerical operators like
gte(greater than or equal) orlteif available, though strict equality works for string representations in many cases.
For complex paths, we recommend testing your JSONPath expression against your API response using online tools before configuring your monitor.