Skip to content

Latest commit

 

History

History
43 lines (36 loc) · 1.62 KB

legacy-output.md

File metadata and controls

43 lines (36 loc) · 1.62 KB
layout title bookmark permalink icon order
page
Example - Serializing Output in the 2019-09 / 2020-12 Format
Legacy Output
/schema/examples/:title/
fas fa-tag
01.4.5

DEPRECATION NOTICE

The Pre202012EvaluationResultsJsonConverter class has been marked obsolete and will be removed in the next major version. {: .prompt-danger }

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.

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
Flag flag flag
List list basic
Hierarchical hierarchical verbose

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. {: .prompt-warning}