Skip to main content
hitspec provides 26 assertion operators organized into six categories. Every assertion follows this pattern:
When the operator is ==, you can omit it: expect status 200 is shorthand for expect status == 200. An unknown operator (contians, =, equals) is a parse error with a suggestion, never a silent ==; see Assertions for the full expected-value grammar (a JSON literal, a /regex/flags, or the rest of the line verbatim).

Equality and Comparison (6 operators)

Numeric comparison coerces strings to numbers when possible. "42" and 42 are considered equal by ==. Objects and arrays are compared as JSON (key order is ignored, numbers compare as numbers). == null matches only a real JSON null; a missing field is not null (use !exists for “absent or null”).

String Operators (5 operators)

Regular expressions use Go’s regexp syntax and are enclosed in forward slashes: /pattern/ or /pattern/i (flags i, m, s, U).
On a JSON response, contains, startsWith, endsWith and matches applied to the whole body see the raw JSON text; applied to an object or array they see its compact JSON encoding.

Existence and Type (3 operators)

For header subjects, exists means the header is present in the response (an empty value still counts) and !exists means it is absent. Supported type values: null, boolean, number, string, array, object. expect body.deletedAt type null passes for a JSON null and fails for an absent field.

Length Operators (5 operators)

Works on strings (counting characters, so "日本語" has length 3), arrays, and objects (counts keys).

Array Operators (5 operators)

includes / !includes

Checks whether an array contains (or does not contain) a specific value:

in / !in

Checks whether a scalar value is a member of a set. List values in square brackets:

each

Applies an assertion to every element in an array. Useful for validating list shapes. After each write an operator and a value, optionally preceded by a path inside the element:
body (or a leading .) names the element itself. An empty array passes. You can also use each with an operator/value map:

Schema and Snapshot (2 operators)

schema

Validates the response body against a JSON Schema file. File paths are relative to the .http file.

snapshot

Compares the response body against a previously saved baseline. A plain run never creates a snapshot: if none exists the assertion fails with “snapshot does not exist (run with —update-snapshots to create)”. Create the baseline once with --update-snapshots; after that, differences cause failure.
Create snapshots, or update them when the response intentionally changes:

Quick Reference

Last modified on October 19, 2026