kinbiko / jsonassert

A Go test assertion library for verifying that two representations of JSON are semantically equal
MIT License
125 stars 16 forks source link

Allow for presence-only checks #5

Closed kinbiko closed 5 years ago

kinbiko commented 5 years ago

Some properties of a JSON payload may be difficult to know in advance. E.g. a timestamp or a UUID or other randomly assigned values.

Proposition

Allow for a string: "<<PRESENCE>>" to not be interpreted literally, but when found in the expected JSON, only check that there is some value for this key in the actual JSON.

If the expected JSON is:

{
  "foo": "<<PRESENCE>>"
}

Then all of the below payloads will match, assuming it is still valid JSON.

{"foo": ""}`
{"foo": {"baz": "bar"}}
{"foo": [1,3, "bar"]}

However, the following payloads should fail.

{"foo": null}
{"foo": "25}

Approach