Customization
Set a value under Customize.aweXpect.Json() for the current
async flow, or under
Customize.aweXpect.Global.Json() for
all tests.
| Value | Default | Summary |
|---|---|---|
DefaultJsonDocumentOptions | AllowTrailingCommas = true | the options to parse JSON strings |
DefaultJsonSerializerOptions | AllowTrailingCommas = true | the options to format JSON values, serialize the subject of IsJsonSerializable and IsJsonSerializedAs and, once set, expected values |
You can change the default
JsonDocumentOptions and the
default JsonSerializerOptions.
Each value is set on its own:
using (Customize.aweXpect.Json().DefaultJsonDocumentOptions.Set(new JsonDocumentOptions
{
AllowTrailingCommas = false,
}))
{
// parses JSON strings without allowing trailing commas
}
To use other JsonDocumentOptions for a single expectation, pass them with WithDocumentOptions(…) wherever
JsonOptions are accepted, also in IsValidJson(o => …):
string track = """{"title": "Let It Be", /* 1970 */ "artist": "The Beatles"}""";
await That(track).IsValidJsonMatching(new { title = "Let It Be" },
o => o.WithDocumentOptions(d => d with { CommentHandling = JsonCommentHandling.Skip }));