Customization
Describes the customization values of aweXpect.Json. They work like the customization of aweXpect.
| Value | Default | Used to |
|---|---|---|
DefaultJsonDocumentOptions | AllowTrailingCommas = true | parse JSON strings |
DefaultJsonSerializerOptions | AllowTrailingCommas = true | format JSON values and serialize the subject of IsJsonSerializedAs |
You can change the default
JsonDocumentOptions and the
default JsonSerializerOptions.
Each value is set on its own and restored when the returned lifetime is disposed:
using (Customize.aweXpect.Json().DefaultJsonDocumentOptions.Set(new JsonDocumentOptions
{
AllowTrailingCommas = false,
}))
{
// parses JSON strings without allowing trailing commas
}
To change a value for all tests, set it on Customize.aweXpect.Global.Json() instead, see
global defaults.
To use other JsonDocumentOptions for a single expectation, pass them to
IsValidJson(o => …) or, wherever JsonOptions are
accepted, with WithJsonOptions(…):
string track = """{"title": "Let It Be", /* 1970 */ "artist": "The Beatles"}""";
await Expect.That(track).IsValidJsonMatching(new { title = "Let It Be" },
o => o.WithJsonOptions(d => d with { CommentHandling = JsonCommentHandling.Skip }));