You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<sup><ahref='/src/Tests/Samples.JsonDocumentSample.verified.txt#L1-L10'title='Snippet source file'>snippet source</a> | <ahref='#snippet-Samples.JsonDocumentSample.verified.txt'title='Start of snippet'>anchor</a></sup>
76
+
<!-- endSnippet -->
77
+
78
+
### Strict Json
79
+
80
+
Note that the above does not result in json files. [This is by design](https://github.com/VerifyTests/Verify/blob/main/docs/serializer-settings.md#not-valid-json). If json files are required then use [UseStrictJson](https://github.com/VerifyTests/Verify/blob/main/docs/serializer-settings.md#usestrictjson)
81
+
82
+
This can be done at the Globally in a ModuleInitializer
83
+
84
+
<!-- snippet: StrictJson -->
85
+
<aid='snippet-StrictJson'></a>
86
+
```cs
87
+
[ModuleInitializer]
88
+
publicstaticvoidInit() =>
89
+
VerifierSettings.UseStrictJson();
90
+
```
91
+
<sup><ahref='/src/TestsStrictJson/ModuleInitializer.cs#L3-L9'title='Snippet source file'>snippet source</a> | <ahref='#snippet-StrictJson'title='Start of snippet'>anchor</a></sup>
92
+
<!-- endSnippet -->
93
+
94
+
Or at the test level
95
+
96
+
<!-- snippet: JsonDocumentSampleStrictJson -->
97
+
<aid='snippet-JsonDocumentSampleStrictJson'></a>
98
+
```cs
99
+
[Test]
100
+
publicTaskJsonDocumentSample()
101
+
{
102
+
varjson=
103
+
"""
104
+
{
105
+
"short": {
106
+
"original": "http://www.foo.com/",
107
+
"short": "foo",
108
+
"error": {
109
+
"code": 0,
110
+
"msg": "No action taken"
111
+
}
112
+
}
113
+
}
114
+
""";
115
+
116
+
vardocument=JsonDocument.Parse(json);
117
+
returnVerify(document)
118
+
.UseStrictJson();
119
+
}
120
+
```
121
+
<sup><ahref='/src/TestsStrictJson/Samples.cs#L4-L28'title='Snippet source file'>snippet source</a> | <ahref='#snippet-JsonDocumentSampleStrictJson'title='Start of snippet'>anchor</a></sup>
<sup><ahref='/src/Tests/Samples.ScrubIgnoreMemberSample.verified.txt#L1-L9'title='Snippet source file'>snippet source</a> | <ahref='#snippet-Samples.ScrubIgnoreMemberSample.verified.txt'title='Start of snippet'>anchor</a></sup>
193
+
<!-- endSnippet -->
194
+
195
+
196
+
### Dates and Guid scrubbing
197
+
198
+
Json values that map to known date and time formats are scrubbed. See [Guids scrubbing](https://github.com/VerifyTests/Verify/blob/main/docs/guids.md) and [Date scrubbing](https://github.com/VerifyTests/Verify/blob/main/docs/dates.md)
199
+
200
+
<!-- snippet: GuidsAndDates -->
201
+
<aid='snippet-GuidsAndDates'></a>
202
+
```cs
203
+
[Test]
204
+
publicTaskGuidsAndDatesSample()
205
+
{
206
+
varjson=
207
+
"""
208
+
{
209
+
"node": {
210
+
"date": "1/10/2023",
211
+
"short": "foo",
212
+
"error": {
213
+
"guid": "123e4567-e89b-12d3-a456-426614174000",
214
+
"msg": "No action taken"
215
+
}
216
+
}
217
+
}
218
+
""";
219
+
220
+
vardocument=JsonDocument.Parse(json);
221
+
returnVerify(document);
222
+
}
223
+
```
224
+
<sup><ahref='/src/Tests/Samples.cs#L54-L77'title='Snippet source file'>snippet source</a> | <ahref='#snippet-GuidsAndDates'title='Start of snippet'>anchor</a></sup>
[Pattern](https://thenounproject.com/term/pattern/1070611/) designed by [Trevor Dsouza](https://thenounproject.com/TDsouza/) from [The Noun Project](https://thenounproject.com/).
0 commit comments