# JsonSchema

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.

Class 

`OfficeIMO.Json`

**Namespace**

`OfficeIMO.Json`

**Assembly**

`OfficeIMO.Core`

**Source revision**

`ba882f6b0d07` with working tree changes

**Source**

[JsonSchema.cs:67](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonSchema.cs#L67)

**Modifiers**

sealed

A JSON Schema (draft 2020-12 or draft 7) that validates [JsonData](/api/core/officeimo-json-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](/api/core/officeimo-json-jsonschema/#method-load-officeimo-json-jsondata-officeimo-json-jsonschemaoptions)
- Method [JsonSchema.Parse](/api/core/officeimo-json-jsonschema/#method-parse-string-officeimo-json-jsonschemaoptions)

Filter members 

Show inherited

## Methods

`public bool IsValid(JsonData instance)` [#](#method-isvalid-officeimo-json-jsondata)

[JsonSchema.cs:92](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonSchema.cs#L92)

Returns whether a value matches, stopping at the first finding.

Parameters

**instance OfficeIMO.Json.JsonData required**

Returns

`bool`

Exceptions

- `ArgumentNullException` – instance is null.
- `JsonSchemaException` – A referenced part of the schema is not valid.

`public static JsonSchema Load(JsonData schema, JsonSchemaOptions? options = null)` [#](#method-load-officeimo-json-jsondata-officeimo-json-jsonschemaoptions)

[JsonSchema.cs:73](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonSchema.cs#L73)

Loads a schema from a JSON value, such as one converted from a YAML document.

Parameters

**schema OfficeIMO.Json.JsonData required**

**options OfficeIMO.Json.JsonSchemaOptions? = null optional**

Returns

`JsonSchema`

Exceptions

- `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](/api/core/officeimo-json-jsonschemaoptions/) is not a valid URI.

`public static JsonSchema Parse(string json, JsonSchemaOptions? options = null)` [#](#method-parse-string-officeimo-json-jsonschemaoptions)

[JsonSchema.cs:67](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonSchema.cs#L67)

Parses a schema from JSON text.

Parameters

**json string required**

**options OfficeIMO.Json.JsonSchemaOptions? = null optional**

Returns

`JsonSchema`

Exceptions

- `FormatException` – The text is not JSON.
- `JsonSchemaException` – The schema is not valid.

`public JsonSchemaValidationResult Validate(JsonData instance)` [#](#method-validate-officeimo-json-jsondata)

[JsonSchema.cs:82](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonSchema.cs#L82)

Validates a value, reporting every finding up to [JsonSchemaOptions.MaxErrors](/api/core/officeimo-json-jsonschemaoptions/).

Parameters

**instance OfficeIMO.Json.JsonData required**

Returns

`JsonSchemaValidationResult`

Exceptions

- `ArgumentNullException` – instance is null.
- `JsonSchemaException` – A referenced part of the schema is not valid.

## Inherited Methods

`public virtual bool Equals(object? obj)` [#](#method-equals-object)

Inherited from object

Parameters

**obj object? required**

Returns

`bool`

`public virtual int GetHashCode()` [#](#method-gethashcode)

Inherited from object

Returns

`int`

`public Type GetType()` [#](#method-gettype)

Inherited from object

Returns

`Type`

`public virtual string? ToString()` [#](#method-tostring)

Inherited from object

Returns

`string?`

## Properties

`public JsonSchemaDraft Draft { get; }` [#](#property-draft)

[JsonSchema.cs:59](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonSchema.cs#L59)

Gets the dialect the schema is read with.

`public JsonData Root { get; }` [#](#property-root)

[JsonSchema.cs:62](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonSchema.cs#L62)

Gets the schema as loaded.

<!-- PowerForge markdown artifact sha256:85C3877F346FBC0DC9C75D4EC022A783E4F250A136C712228D3389AF4616AF41 -->
