-
-
Notifications
You must be signed in to change notification settings - Fork 535
JsonSchema4
Rico Suter edited this page Aug 17, 2016
·
14 revisions
Package: NJsonSchema
The JsonSchema4
class can be used as follows:
var schema = JsonSchema4.FromType<Person>();
var schemaData = schema.ToJson();
var jsonData = "{...}";
var errors = schema.Validate(jsonData);
foreach (var error in errors)
Console.WriteLine(error.Path + ": " + error.Kind);
schema = JsonSchema4.FromJson(schemaData);
Any property which is not specified in JSON Schema will be serialized and deserialized from the ExtensionData
property on the JsonSchema4
class.
You can either validate a JSON string or an already deserialized JToken
. NJsonSchema cannot retrieve the initial date/time values from a JToken
and thus may have problems when validating against string patterns. This is why you should prefer the Validate(string)
method which handles date/time handling with the correct serializer settings.
Type inheritance (required for C# and TypeScript generation) is described via the allOf
field with the following rules:
- Schemas in
allOf
with a type ofObject
are treated as inherited schemas (exposed via theInheritedSchemas
property) - Schemas in
allOf
with no type (i.e. typeNone
) are merged into the parent schema (i.e. properties are combined and exposed via theAllProperties
property)