Comparison rules
Exactly how two responses are compared — status, headers, JSON bodies, arrays, numbers, null versus missing, correlated identifiers — and what each outcome and reason code means.
For every compared step Parity has two observed responses, one from each environment, and a set of rules. Comparison is a pure function of those inputs: the same pair of responses under the same rules always produces the same differences, in the same order, with the same wording. No model is involved.
Rules come from comparison in parity.yaml, refined per source, per workflow and per step.
#Status
status | Two statuses differ when |
|---|---|
exact (default) | The codes are not equal. |
class | The first digits are not equal (any 2xx equals any 2xx). |
ignore | Never. |
When the status class changes and both bodies are JSON, the bodies are reported once, as a whole, instead of field by field — a success document and an error document are two different documents, not one document with many changed fields:
✗ POST /orders · `items[0].quantity` below its minimum (0) openapi · 1ms
~ Status changed from 422 Unprocessable Content to 201 Created.
~ The response body is a different document (422 Unprocessable Content versus 201 Created);
compared as a whole because the status class changed.#Headers
No response header is compared unless you list it in comparison.headers. Names are case-insensitive; a header sent more than once is compared as its values joined with , .
comparison:
headers: [content-type, cache-control]A listed header can be changed, added or removed (header_changed, header_added, header_removed).
#Bodies
How a body is read depends on what was received:
- no bytes → empty;
- valid UTF-8 that parses as JSON, when the
Content-Typementionsjsonor the text starts with{or[→ JSON; - other valid UTF-8 → text;
- anything else → binary, compared by length and SHA-256.
body | Behaviour |
|---|---|
semantic (default) | JSON is compared structurally under the rules below. Member order and whitespace do not matter. |
exact | The two JSON documents must serialise identically, member order included. |
ignore | Bodies are not compared. |
Text bodies must be equal; the first differing line and column are reported. If the two sides are of different kinds (JSON versus text, a body versus none) that is a difference in itself (body_format_changed or body_changed).
#Semantic comparison
The two JSON documents are walked together. At each location:
| Baseline and candidate | Result |
|---|---|
| Equal scalars | No difference. |
| Scalars of the same type with different values | value_changed |
A value on one side and null on the other | value_changed |
| Different types (number versus string, object versus array, …) | type_changed |
| Member present on one side only | field_added / field_removed |
Member null on one side and absent on the other | null_vs_missing (see below) |
| Two objects, two arrays | Compared recursively. |
Integers are compared exactly. Other numbers are compared numerically, so 1.0 and 1 are equal.
#Ignore paths
comparison.ignore lists JSONPaths that are allowed to differ. An ignored location is skipped together with everything beneath it, whether it changed, was added or was removed.
comparison:
ignore:
- $.requestId # one member at the root
- $..created_at # this member at any depth
- $.items[*].etag # in every element of an array
- $.meta # a whole subtree#Supported JSONPath
Parity implements a deliberately small JSONPath dialect, used for ignore rules, tolerances, array rules, redaction paths, extract and assert:
| Syntax | Selects |
|---|---|
$ | The root. A leading $ is optional: data.id means $.data.id. |
.name or ['name'] | A member. Use the bracket form for names with dots or spaces. |
[0], [-1] | An array element by index; negative indices count from the end. |
[*] or .* | Every element or member. |
..name | A member at any depth. |
..* | Everything beneath. |
Filters ([?(@.price > 10)]), slices ([0:2]) and unions are not supported, and are rejected when the configuration is loaded:
error: jp.yaml: invalid JSONPath `$.items[?(@.x)]`: `[?(@.x)]` is not an index, `*` or a quoted name#Numeric tolerances
numeric_tolerance is an absolute tolerance for every number. tolerances sets an absolute and/or relative tolerance for specific paths; the first matching rule wins and replaces the global tolerance at that location.
comparison:
numeric_tolerance: 0
tolerances:
- path: $..tax
absolute: 0.005
- path: $.metrics.p95_ms
relative: 0.2Two numbers are equal when their difference is within the absolute tolerance, or within the relative tolerance multiplied by the larger of their magnitudes. A reported numeric change carries its delta:
~ `$.tax` changed from 27.7 to 27.70008403361345 (Δ +0.00008403361345088).When no tolerance is configured and the delta is tiny relative to the values, the message says that it looks like floating-point noise that a tolerance would absorb. Parity does not apply one for you.
#Arrays
| Semantics | How it is chosen | Behaviour |
|---|---|---|
| Ordered | arrays: ordered (default) | Elements are compared by position. |
| Unordered | arrays: unordered, or an array_rules entry with order: unordered | Elements are matched by equality regardless of position. |
| Keyed | An array_rules entry with key: <member> | Elements are matched by the value of that member. |
comparison:
arrays: ordered
array_rules:
- path: $.tags
order: unordered
- path: $.line_items
key: skuThe first array_rules entry whose path matches an array applies to it.
Ordered arrays are aligned, not just zipped.
- Same length, same elements, different order → a single
order_changeddifference, with a hint that the array can be compared as unordered if order is not part of the contract. - Different lengths → the arrays are aligned on their longest common subsequence, so one inserted element is reported as one
element_addedinstead of making every later element look changed.
+ Element `$.items[1]` was added
({"id":"pay_6bfe93df4c","order_id":"ord_f7a1f55fe3","amount":129,"status":"captu…).Unordered arrays pair up elements that are equal under the rules (ignores, tolerances and correlation included). Whatever is left over is compared pairwise, then reported as added or removed.
Keyed arrays pair elements whose key values match. An element whose key exists on one side only is added or removed; elements without the key are compared by position among themselves.
Alignment is bounded: for very large arrays (more than 250,000 element pairs) Parity falls back to positional comparison.
#Null versus missing
By default {"phone": null} and {} are different, and reported as null_vs_missing:
- `$.phone` is null in the baseline but absent from the candidate.Clients in typed languages often treat the two differently, which is why this is not folded into "equal". If your API's contract says they are interchangeable, set:
comparison:
null_vs_missing: equivalent#Identifier correlation
Two environments generate different identifiers for the same thing. In a workflow, a value captured with extract is recorded as a pair — order_id is ord_1014 in the baseline and ord_af278cf8fa in the candidate — and later comparisons treat the two as the same value:
- a string that is exactly the paired value on each side is equal;
- a longer string that becomes equal once the paired values are substituted is equal (
/orders/ord_1014/itemsversus/orders/ord_af278cf8fa/items); substitution inside longer strings only applies to values of six characters or more; - paired numbers and booleans are equal when they appear as that exact pair;
- the same applies to compared headers and to the key of a keyed array.
Nothing is suppressed by pattern ("looks like a UUID") or by position. A difference disappears only when the two values are exactly a pair that the workflow extracted. Turn it off for one variable with correlate: false.
Single requests have nothing to correlate. A scenario generated from OpenAPI is one request; if the response contains a generated ID, it will be reported as changed. Either ignore the field for that source —
sources:
- openapi: ./openapi.yaml
compare:
ignore: [$.id]— or cover the operation with a workflow.
#Nondeterminism detection
Some fields differ on every call: timestamps, request IDs, uptime counters. When a scenario comes out changed and it is read-only (every request is GET, HEAD, OPTIONS or TRACE), Parity sends the scenario to the baseline once more and compares the baseline with itself. A difference at a location that also differs between the two baseline runs is marked nondeterministic.
- If every difference in the scenario is nondeterministic, the scenario is inconclusive with reason
nondeterministic, and the message lists the paths to ignore. - If some differences remain, the scenario is changed; the nondeterministic ones stay in the report, marked.
? GET /health · valid request
Every difference also appears between two runs of the baseline, so it cannot be attributed to
the candidate. Add ignore rules for: $.uptime_ms.Scenarios that mutate are never replayed, because replaying would change state. For those, add ignore rules yourself. Disable the check with execution.nondeterminism_check: off.
#"Excluded by rules"
A location is excluded by rules when the two sides differ there but no difference is reported because a rule says so: the path is ignored, the numbers are within tolerance, the values are a correlated pair, or null and missing are configured as equivalent. The comparison workspace marks these lines with ≈ so you can see what the rules are hiding; they never affect the outcome.
#Outcomes
Every scenario ends in exactly one outcome.
| Outcome | Mark | Meaning | Policy |
|---|---|---|---|
unchanged | Every compared step matched under the rules. | — | |
changed | ✗ | At least one deterministic difference. | unexpected_changes |
error | ! | An environment could not be used. Nothing can be concluded about behaviour. | environment_errors |
inconclusive | ? | The scenario ran but did not test what it was meant to. | inconclusive |
skipped | – | Not sent. | reported as a warning |
Behavioural change, environment error and inconclusive are deliberately separate: an outage in a test environment is not a regression, and it is not a pass either.
#Reason codes
Scenarios that are not simply unchanged or changed carry a reason (text) and a reason_code in the report.
| Reason code | Outcome | When |
|---|---|---|
baseline_unreachable | error | The request to the baseline failed (connection, DNS, TLS, protocol) while the candidate answered. |
candidate_unreachable | error | The request to the candidate failed while the baseline answered. |
both_unreachable | error | Both requests failed. |
timeout | error | Every failure was a timeout. |
gateway_error | error | A response had a status listed in execution.infrastructure_statuses (502, 503, 504 by default) that the step did not expect. |
auth_rejected | inconclusive | Both environments answered 401 or 403 and the step did not expect it. |
rate_limited | inconclusive | Either environment answered 429 and the step did not expect it. |
nondeterministic | inconclusive | Every difference also appears between two runs of the baseline. |
extraction_failed | inconclusive | An extract found nothing (or null) in one of the responses; later steps depend on it. |
expectation_unmet | inconclusive | An expect status or an assert failed in both environments, or a setup step failed. |
response_too_large | inconclusive | A response exceeded execution.max_response_bytes. |
template_error | inconclusive | A request could not be built (an undefined variable at run time, a missing $env variable). |
mutation_blocked | skipped | The scenario mutates and an environment is not authorised for mutations. |
dry_run | skipped | The run used --dry-run. |
cancelled | skipped | The run was cancelled or hit execution.max_duration_s. |
A 401 from only one environment is not auth_rejected: one version rejecting a request the other accepts is a behavioural difference, and is reported as a status change.
When a difference is found and the scenario stopped early, the outcome is changed and the reason explains where it stopped.
#Difference kinds
Every difference in a report has a kind, a location (status, header, body or assertion), a path, both values and a message.
| Kind | Meaning |
|---|---|
status_changed | The status code differs under the status mode. |
header_changed, header_added, header_removed | A compared header differs. |
value_changed | Same location, same type, different value (or a value versus null). |
type_changed | The JSON type at a location changed. |
field_added, field_removed | An object member exists on one side only. |
null_vs_missing | A member is null on one side and absent on the other. |
element_added, element_removed | An array element exists on one side only. |
order_changed | An ordered array holds the same elements in a different order. |
body_format_changed | The body kinds differ (JSON versus text, …). |
body_changed | Whole-body difference: text, binary, exact mode, or a changed status class. |
assertion_diverged | An assert or expect holds in one environment and fails in the other. |