equalToJson
and matchesJsonPath
, which are described
in detail in this article.
Matching via JSON equality
TheequalToJson
match operator performs a semantic comparison of the input JSON
against the expected JSON. This has a number of advantages over a straight string
comparison:
- Ignores differences in whitespace
- Can be configured to ignore differences in array order
- Can be configured to ignore extra object attributes
- Supports placeholders so that specific attributes can be excluded from the comparison
equalToJson
will match only if all of the elements in the input JSON
are the same as the expected JSON, arrays are in the same order and no additional
attributes are present.
For instance, given an expected JSON document like

sizes
order would cause a non-match:
Ignoring array order
Sometimes the order of elements in an array is unimportant and can change arbitrarily between multiple requests. In this case it’s undesirable for your stub match to fail due to array order, so to remedy this you can simply tick “Ignore array order”.
Ignoring extra elements
If you’re only interested in matching a specific set of JSON elements and don’t mind if additional elements are present you can tick “Ignore extra elements”.
Using placeholders to ignore specific JSON attributes
If you want to check that an element is present, but don’t care what the value is then you can use JSONUnit placeholder syntax to achieve this. Note: unlike with XML placeholders this is enabled by default. For instance, given the following configuration:
${json-unit.ignore}
, the element’s type is also ignored (in addition to its value),
so in the above case a string, boolean etc. could have been used in place of the numeric ID.
If you want to constrain an element to a specific type but still ignore the value
you can use one of the following placeholders:
${json-unit.regex}[A-Z]+
(any Java-style regular expression can be used)${json-unit.any-string}
${json-unit.any-boolean}
${json-unit.any-number}
Matching via JSONPath - matchesJsonPath
JSONPath is an expression language,
similar in concept to XPath that permits elements or collections of elements
to be queried from a JSON document.
WireMock Cloud supports stub matching using JSONPath expressions, optionally sub-matching
the result using WireMock Cloud’s own operators (equalTo
, matches
etc.).
Given the following configration:

Expression only vs. expression + sub-match
It is possible to match a JSON document without a sub-match by selecting “is present” from the drop-down:
Common JSONPath examples
Matching on a specific array element by position.$.sizes[1]
equal to
M
would match:
$.addresses[?(@.type == 'business')].postcode
contains
N11NN
would match:
contains
in this instance as a JSONPath expression containing
a query part (between the [?
and ]
) will always return a collection
of results.
Matching an element found recursively.
$..postcode
contains
N11NN
would match: