JSON matchers

If the exact value of a field is unknown, you can use JSON matchers to make sure it has a certain property or shape.

JSON matchers work more or less like placeholders in practice.

And assert body.ignoring("city", "realName", "publisher.location").is(
  """
  {
    "name": "<favorite-superhero>",
    "hasSuperpowers": *any-boolean*,
    "publisher": {
      "name": *any-string*,
      "foundationYear": *any-positive-integer*
    }
  }
  """
)

You just need to replace the value of the field by one of the built-in JSON matchers without quotes.

Here are the available matchers:

This feature is still under experimentation and comes with a couple of limitations:

  • it is not yet possible to register custom JSON matchers
  • matchers are not supported for JSON arrays assertions via asArray