Home JsonSchema Class
JsonSchema Class
Cancel

JsonSchema Class

Namespace: Json.Schema

Inheritance: JsonSchema 🡒 object

Implemented interfaces:

  • IBaseDocument

Represents a JSON Schema.

Fields

NameTypeSummary
EmptyJsonSchemaThe empty schema {}. Functionally equivalent to Json.Schema.JsonSchema.True.
FalseJsonSchemaThe false schema. Fails all instances.
TrueJsonSchemaThe true schema. Passes all instances.

Properties

NameTypeSummary
BaseUriUriGets the base URI that applies to this schema. This may be defined by a parent schema.
BoolValuebool?For boolean schemas, gets the value. Null if the schema isn’t a boolean schema.
DeclaredVersionSpecVersionGets the specification version as determined by analyzing the $schema keyword, if it exists.
IsResourceRootboolGets whether the schema defines a new schema resource. This will only be true if it contains an $id keyword.
ItemIJsonSchemaKeywordGets the keyword class by keyword name.
KeywordsIReadOnlyCollection<IJsonSchemaKeyword>Gets the keywords contained in the schema. Only populated for non-boolean schemas.

Methods

Evaluate(JsonNode root, EvaluationOptions options)

Evaluates an instance against this schema.

Declaration

1
public EvaluationResults Evaluate(JsonNode root, EvaluationOptions options)
ParameterTypeDescription
rootJsonNodeThe root instance.
optionsEvaluationOptionsThe options to use for this evaluation.

Returns

A Json.Schema.EvaluationResults that provides the outcome of the evaluation.

FromFile(string fileName)

Loads text from a file and deserializes a Json.Schema.JsonSchema.

Declaration

1
public static JsonSchema FromFile(string fileName)
ParameterTypeDescription
fileNamestringThe filename to load, URL-decoded.

Returns

A new Json.Schema.JsonSchema.

Remarks

The filename needs to not be URL-encoded as System.Uri attempts to encode it.

FromFile(string fileName, JsonSerializerOptions options)

Loads text from a file and deserializes a Json.Schema.JsonSchema.

Declaration

1
public static JsonSchema FromFile(string fileName, JsonSerializerOptions options)
ParameterTypeDescription
fileNamestringThe filename to load, URL-decoded.
optionsJsonSerializerOptionsSerializer options.

Returns

A new Json.Schema.JsonSchema.

Remarks

The filename needs to not be URL-encoded as System.Uri attempts to encode it.

FromStream(Stream source)

Deserializes a Json.Schema.JsonSchema from a stream.

Declaration

1
public static ValueTask<JsonSchema> FromStream(Stream source)
ParameterTypeDescription
sourceStreamA stream.

Returns

A new Json.Schema.JsonSchema.

FromStream(Stream source, JsonSerializerOptions options)

Deserializes a Json.Schema.JsonSchema from a stream.

Declaration

1
public static ValueTask<JsonSchema> FromStream(Stream source, JsonSerializerOptions options)
ParameterTypeDescription
sourceStreamA stream.
optionsJsonSerializerOptionsSerializer options.

Returns

A new Json.Schema.JsonSchema.

FromText(string jsonText)

Deserializes a Json.Schema.JsonSchema from text.

Declaration

1
public static JsonSchema FromText(string jsonText)
ParameterTypeDescription
jsonTextstringThe text to parse.

Returns

A new Json.Schema.JsonSchema.

FromText(string jsonText, JsonSerializerOptions options)

Deserializes a Json.Schema.JsonSchema from text.

Declaration

1
public static JsonSchema FromText(string jsonText, JsonSerializerOptions options)
ParameterTypeDescription
jsonTextstringThe text to parse.
optionsJsonSerializerOptionsSerializer options.

Returns

A new Json.Schema.JsonSchema.

GetAnchor(string anchorName)

Gets a defined anchor.

Declaration

1
public JsonSchema GetAnchor(string anchorName)
ParameterTypeDescription
anchorNamestringThe name of the anchor (excluding the #)

Returns

The associated subschema, if the anchor exists, or null.

GetConstraint(JsonPointer relativeEvaluationPath, JsonPointer baseInstanceLocation, JsonPointer relativeInstanceLocation, EvaluationContext context)

Builds a constraint for the schema.

Declaration

1
public SchemaConstraint GetConstraint(JsonPointer relativeEvaluationPath, JsonPointer baseInstanceLocation, JsonPointer relativeInstanceLocation, EvaluationContext context)
ParameterTypeDescription
relativeEvaluationPathJsonPointerThe relative evaluation path in JSON Pointer form. Generally this will be a keyword name, but may have other segments, such as in the case of properties which also has the property name.
baseInstanceLocationJsonPointerThe base location within the instance that is being evaluated.
relativeInstanceLocationJsonPointerThe location relative to baseInstanceLocation within the instance that is being evaluated.
contextEvaluationContextThe evaluation context.

Returns

A schema constraint.

Remarks

The constraint returned by this method is cached by the Json.Schema.JsonSchema object. Different evaluation paths to this schema object may result in different constraints, so a new constraint is saved for each dynamic scope.

GetKeyword()

Gets a specified keyword if it exists.

Declaration

1
public T GetKeyword()

Returns

The keyword if it exists; otherwise null.

TryGetKeyword(out T keyword)

Declaration

1
public bool TryGetKeyword(out T keyword)

Returns

TryGetKeyword(string keywordName, out T keyword)

Declaration

1
public bool TryGetKeyword(string keywordName, out T keyword)

Returns

Contents