JsonSchema
OfficeIMO.Json
A JSON Schema (draft 2020-12 or draft 7) that validates JsonData values, such as the contents of a YAML, TOML or JSON configuration file. Findings carry the JSON Pointer of the value, the schema path of the failing keyword, and the value's line and column in the source.
Inheritance
- object
- JsonSchema
Remarks
Supported keywords: type, enum, const; multipleOf, minimum, maximum, exclusiveMinimum, exclusiveMaximum; minLength, maxLength, pattern, format; prefixItems, items, contains, minContains, maxContains, minItems, maxItems, uniqueItems, unevaluatedItems; properties, patternProperties, additionalProperties, propertyNames, required, minProperties, maxProperties, dependentRequired, dependentSchemas, unevaluatedProperties; allOf, anyOf, oneOf, not, if/then/else; $ref, $dynamicRef, $defs, $id, $anchor and $dynamicAnchor. Draft 7 schemas also read definitions, array items with additionalItems, and dependencies. Other keywords, including $vocabulary and the content keywords, are annotations only. References resolve within the loaded document; anything else goes to , and nothing is fetched otherwise. Patterns use .NET regular expressions with a timeout. A loaded schema is safe to use from several threads.
Usage
Explore 2 API references to this type
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Returned or exposed by 2
- Method JsonSchema.Load
- Method JsonSchema.Parse
Methods
public bool IsValid(JsonData instance) #Returns whether a value matches, stopping at the first finding.
Parameters
- instance OfficeIMO.Json.JsonData
Returns
boolExceptions
ArgumentNullException– instance is null.JsonSchemaException– A referenced part of the schema is not valid.
public static JsonSchema Load(JsonData schema, JsonSchemaOptions? options = null) #Loads a schema from a JSON value, such as one converted from a YAML document.
Parameters
- schema OfficeIMO.Json.JsonData
- options OfficeIMO.Json.JsonSchemaOptions? = null
Returns
JsonSchemaExceptions
ArgumentNullException– schema is null.JsonSchemaException– The schema is not an object or boolean, a keyword has a value of the wrong type, or JsonSchemaOptions.BaseUri is not a valid URI.
public static JsonSchema Parse(string json, JsonSchemaOptions? options = null) #Parses a schema from JSON text.
Parameters
- json string
- options OfficeIMO.Json.JsonSchemaOptions? = null
Returns
JsonSchemaExceptions
FormatException– The text is not JSON.JsonSchemaException– The schema is not valid.
public JsonSchemaValidationResult Validate(JsonData instance) #Validates a value, reporting every finding up to JsonSchemaOptions.MaxErrors.
Parameters
- instance OfficeIMO.Json.JsonData
Returns
JsonSchemaValidationResultExceptions
ArgumentNullException– instance is null.JsonSchemaException– A referenced part of the schema is not valid.