JSON Path Assertions: Validate Nested API Responses
Your API returns 200 OK. The body looks like JSON. But is $.data.user_id actually populated? Is the balance positive? Is the error field null? JSON Path assertions tell you.
What is a JSON Path assertion?
A JSON Path assertion is a rule that points to a specific field inside a JSON response body and validates its value. Instead of scanning the entire body for a pattern (regex), you target exactly the field you care about.
// Response:
{
"status": "ok",
"data": {
"user_id": 42,
"balance": 1500,
"plan": "pro"
},
"error": null
}
// Assertions:
$.status == "ok" ✓ passes
$.data.balance >= 100 ✓ passes
$.error is_null ✓ passes
$.data.plan == "free" ✗ fails → alert firesWhich Operators Does CheckAPI Support for JSON Path Assertions?
CheckAPI supports 11 operators for JSON Path assertions:
| Operator | Use case |
|---|---|
| == | Exact match — status must be "ok" |
| != | Must not equal — code must not be 0 |
| > | >= < <= |
| contains | String contains a substring |
| not_contains | String must not contain a substring |
| is_null | Field must be null |
| is_not_null | Field must not be null — data must be populated |
| exists | Field key must exist in the response |
What Are Real-World JSON Path Assertion Examples?
Health check endpoint
// GET /health
{
"status": "ok",
"db": "connected",
"cache": "connected",
"version": "2.4.1"
}
// Assertions:
$.status == "ok"
$.db == "connected"
$.cache == "connected"
$.version is_not_nullPayment API
// POST /payments/process
{
"success": true,
"transaction_id": "txn_abc123",
"amount_charged": 4999,
"error": null
}
// Assertions:
$.success == true
$.transaction_id exists
$.amount_charged > 0
$.error is_nullList endpoint (data must not be empty)
// GET /api/products
{
"data": [...],
"total": 142,
"page": 1
}
// Assertions:
$.total > 0
$.data is_not_nullShould You Use AND or OR Logic for JSON Path Assertions?
By default, all assertions are evaluated with AND logic — every assertion must pass for the check to be green. You can switch individual assertions to OR in the Assertions tab, which means the check passes if at least one assertion is true.
How Many JSON Path Assertions Can You Set Per Monitor?
CheckAPI supports up to 10 JSON Path assertions per monitor. This is enough to comprehensively validate the critical fields of any API response in a single check — no code required.
Can You Combine JSON Path Assertions with Regex?
JSON Path and Regex aren't mutually exclusive. A common pattern is to use Regex for a quick top-level sanity check (e.g. error field is null) and JSON Path for precise field-level validation (e.g. balance is positive, user_id exists). Both run on every check.
Set up JSON Path assertions
Available on all plans including Free. Create your first monitor with JSON Path assertions in under 2 minutes.
Start for Free