Json.NET supports the JSON Schema standard via the T:Newtonsoft.Json.Schema.JsonSchema and T:Newtonsoft.Json.JsonValidatingReader classes. It sits under the N:Newtonsoft.Json.Schema namespace.

JSON Schema is used to validate the structure and data types of a piece of JSON, similar to XML Schema for XML. Read more about JSON Schema at json-schema.org http://json-schema.org/ _blank

# Validating with JSON Schema

The simplest way to check if JSON is valid is to load the JSON into a JObject or JArray and then use the M:Newtonsoft.Json.Schema.Extensions.IsValid(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Schema.JsonSchema) method with the JSON Schema.

Validate JSON with IsValid

To get validation error messages use the M:Newtonsoft.Json.Schema.Extensions.IsValid(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Schema.JsonSchema,System.Collections.Generic.IList{System.String}@) or M:Newtonsoft.Json.Schema.Extensions.Validate(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Schema.JsonSchema,Newtonsoft.Json.Schema.ValidationEventHandler) overloads.

Validate JSON with IsValid

Internally IsValid uses T:Newtonsoft.Json.JsonValidatingReader to perform the JSON Schema validation. To skip the overhead of loading JSON into a JObject/JArray, validating the JSON and then deserializing the JSON into a class, JsonValidatingReader can be used with JsonSerializer to validate JSON while the object is being deserialized.

Validate JSON with JsonValidatingReader

# Creating JSON Schemas

The simplest way to get a T:Newtonsoft.Json.Schema.JsonSchema object is to load it from a string or a file.

Creating JSON Schemas from strings or files

It is also possible to create JsonSchema objects in code.

Create new JSON Schemas in code

T:Newtonsoft.Json.Schema.JsonSchema
T:Newtonsoft.Json.JsonValidatingReader