JSON paths in API assertions: $.items[0].id, lengths and odd keys

Most checks on a JSON response come down to "this field has this value". In Requestarium you write that as an assertion with a JSON body source and a path, on the request's Tests tab, without code. The same paths are used by Save to variable in test suites and in {{nodes.…}}-style references.

Here's what a path can say.

The example response

JSON
{
  "id": "ord_42",
  "status": "paid",
  "customer": { "id": "cus_7", "email": "[email protected]" },
  "items": [
    { "sku": "DESK-1", "quantity": 1, "price": 499 },
    { "sku": "LAMP-2", "quantity": 2, "price": 39 }
  ],
  "meta": { "x-trace-id": "a1b2", "created at": "2026-11-24T10:00:00Z" }
}

Paths

PathValue
$.id or id"ord_42"
$.customer.email"[email protected]"
$.items[0].sku"DESK-1"
$.items[1].quantity2
$.items.length2
$['meta']['x-trace-id']"a1b2"
$.meta['created at']"2026-11-24T10:00:00Z"
$the whole object

Assertions that use them

CheckSourcePathOperatorExpected
Order is paidJSON body$.statusequalspaid
Has a customerJSON body$.customer.idexists
Two line itemsJSON body$.items.lengthequals2
At least one itemJSON body$.items.lengthat least1
First SKU looks rightJSON body$.items[0].skumatches regex^[A-Z]+-\d+$
Email is a stringJSON body$.customer.emailis typestring
Same customer as beforeJSON body$.customer.idequals{{customerId}}

Expected values can use {{variables}}, including ones the post-response script set a moment earlier, so "the order belongs to the customer we just created" needs no code.

Generate from response on the Tests tab writes starter checks for you: status, content type, a response-time budget and an exists check for each top-level field. Start there and tighten them.

Arrays: first item vs any item

A path picks one position. $.items[0].sku equals DESK-1 passes only if the desk is first. When order doesn't matter, check something order-free (the length, or a schema with items), or use a script:

JavaScript
pm.test('the lamp is in the order', () => {
  const skus = pm.response.json().items.map((i) => i.sku);
  pm.expect(skus).to.include('LAMP-2');
});

Every item

"Every item has a positive price" is a JSON Schema job. Use source JSON body, path $.items, operator matches JSON schema:

JSON
{
  "type": "array",
  "items": {
    "type": "object",
    "required": ["sku", "quantity", "price"],
    "properties": { "price": { "type": "integer", "minimum": 1 } }
  }
}

Top-level arrays

If the body is an array, the path starts at it: $[0].id, $.length.

Saving a value for later

In a test suite, Save to variable on a request takes the same paths: $.access_token from a login response becomes {{access_token}} for every step after it. A missing value fails the step, so a login without a token stops the suite instead of sending twenty requests with an empty header.

In a script, the equivalent is:

JavaScript
pm.environment.set('orderId', pm.response.json().id);

When a path isn't enough

Use a post-response script when the check depends on two fields, a calculation, or a search through the array:

JavaScript
const o = pm.response.json();
pm.test('total matches items', () => {
  const sum = o.items.reduce((s, i) => s + i.quantity * i.price, 0);
  pm.expect(o.total).to.equal(sum);
});

Assertions and script tests show up in the same results list, failures first, with expected and actual values.