Home Example - Serializing Output in the 2019-09 / 2020-12 Format
Example - Serializing Output in the 2019-09 / 2020-12 Format
Cancel

Example - Serializing Output in the 2019-09 / 2020-12 Format

DEPRECATION NOTICE

The Pre202012EvaluationResultsJsonConverter class has been marked obsolete and will be removed in the next major version.

The 2019-09 and 2020-12 JSON Schema specifications define output formats that can be difficult to work with.

For future versions of the specification, the output is undergoing some changes. This new format is the default for JsonSchema.Net, however the evaluation results can still (mostly) be serialized to the 2019-09 / 2020-12 formats by using the Pre202012EvaluationResultsJsonConverter.

1
2
3
4
5
6
7
8
9
10
11
12
13
var schema = JsonSchema.FromText(" ... ");
var options = new EvaluationOptions
{
    OutputFormat = OutputFormats.List
};
var instance = JsonNode.Parse(" ... ");
var results = schema.Evaluate(instance, options);

var serializerOptions = new JsonSerializerOptions
{
    Converters = { new Pre202012EvaluationResultsJsonConverter() }
};
var output = JsonSerializer.Serialize(results, serializationOptions);

The OutputFormat option still controls which format you’ll get:

OutputFormat“New” format (default)“Legacy” format
Flagflagflag
Listlistbasic
Hierarchicalhierarchicalverbose

The “detailed” format defined by the specification is not supported since it requires some advanced logic (which was never properly specified) to pare down the nodes.