# Check JSONPath Matches Before Writing the Assertion

> A path that selects the first order can pass while selecting the wrong record. Test a conditional JSONPath against a paid and unpaid order before keeping it in a test.

- Author: [Shashank Rawlani](https://shashank.rawlani.com)

- Published: 2026-10-07T05:30:00.000Z

- Updated: 2026-10-14T10:26:49.503Z

- Category: Tools & Reviews

- Canonical source: https://automationtester.in/blog/tools-reviews/find-jsonpath-matches-before-asserting

- Tags: jsonpath, api-testing, test-assertions, json

Put a sample response and a JSONPath expression into the [JSONPath Tester](https://automationtester.in/tools/jsonpath-tester). It shows the values that match and their count as you edit. Keep the expression only after checking it against both a matching and a non-matching response.

A test extracts the first order ID and passes, even though the order is unpaid. The path selected a position, not the record the test meant to inspect. A filter can express the condition, but it is easy to type one that matches nothing or selects several records.

## Find the paid order ID

Replace the sample JSON in the left pane with this small response:

```
{"orders":[
  {"id":"A-17","total":499,"paid":true},
  {"id":"A-18","total":0,"paid":false}
]}
```

[Try this in JSONPath Tester](https://automationtester.in/tools/jsonpath-tester#p=eyJ2IjoxLCJpbnB1dCI6IntcIm9yZGVyc1wiOltcbiAge1wiaWRcIjpcIkEtMTdcIixcInRvdGFsXCI6NDk5LFwicGFpZFwiOnRydWV9LFxuICB7XCJpZFwiOlwiQS0xOFwiLFwidG90YWxcIjowLFwicGFpZFwiOmZhbHNlfVxuXX0iLCJleHByIjoiJC5vcmRlcnNbPyhALnBhaWQgPT0gdHJ1ZSldLmlkIn0)

Enter the complete expression `$.orders[?(@.paid == true)].id`. The tool reports `1 match` and shows `["A-17"]` in the result pane. The selection is conditional on `paid`; `$.orders[0].id` would happen to return the same value for this response but would silently change meaning if the array order changed.

Now set the first order's `paid` value to `false`. The result becomes zero matches. This second check matters: a path that always returns the first ID can look correct on one friendly fixture.

## Know the supported syntax

This tool supports child names, array indexes and wildcards, slices, recursive descent, and simple filters such as `@.paid == true` or `@.total > 0`. It is a small browser evaluator, not a promise that every expression in RFC 9535 works here. For example, adding `&& @.total > 0` to the filter above produces `Unsupported filter literal` rather than a combined condition.

That error is preferable to a quiet zero-match result. A zero can mean the query is valid but no order qualifies; an error means the expression itself needs work. The tool also reports invalid JSON separately. If your test runner uses a different JSONPath library, run the final expression there too, because supported syntax and result ordering can differ.

## Turn a query into a useful assertion

Do not assert only that the returned array is non-empty. For this response, assert that exactly one order matches and that its ID is `A-17`. A later extra paid order should then force a decision about whether the test expects one order or many. [JSON Diff](https://automationtester.in/tools/json-diff) can help locate a changed field when a saved fixture stops matching.

**Why do I see an array for one match?** A JSONPath query selects a set of nodes. The tool displays their values as an array, even when the count is one.

**Does no match mean the expression is wrong?** Not by itself. Try a fixture that should match and one that should not. The pair separates a correct negative result from a path aimed at the wrong field.

## Check the assertion against two cases

Take one JSONPath assertion from a test. Run it on a positive fixture and a negative fixture, then record the expected count and values. Keep both fixtures with the test so the selection rule remains reviewable.

## JSONPath syntax and tool reference

- [RFC 9535, JSONPath](https://www.rfc-editor.org/info/rfc9535/): the standard query model for selecting JSON values.

- [AutomationTester.in JSONPath Tester](https://automationtester.in/tools/jsonpath-tester): the browser input, expression, match count, and result pane.

## Continue reading on AutomationTester.in

- [Create a Failure Triage Toolkit Before the Next Flake](https://automationtester.in/blog/tools-reviews/failure-triage-toolkit-before-flake)
- [Test Cron Schedules by Their Fire Times, Not Their Strings](https://automationtester.in/blog/tools-reviews/verify-cron-schedules-time-zones-boundaries)
- [Build a k6 Load Model from Real Traffic, Not a VU Count](https://automationtester.in/blog/tools-reviews/generate-k6-load-model-traffic-assumptions)
- [Freeze Generated Test Data Before CI Needs It](https://automationtester.in/blog/tools-reviews/freeze-generated-test-data-fixtures)
- [Review Required Fields in a Generated JSON Schema](https://automationtester.in/blog/tools-reviews/review-generated-json-schema-required-fields)

Source: [Check JSONPath Matches Before Writing the Assertion](https://automationtester.in/blog/tools-reviews/find-jsonpath-matches-before-asserting) by Shashank Rawlani.
