1
<?xml version="1.0" encoding="utf-8"?>
2
<topic id="JsonSchema" revisionNumber="1">
3
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
5
<para>Json.NET supports the JSON Schema standard via the <codeEntityReference>T:Newtonsoft.Json.Schema.JsonSchema</codeEntityReference>
6
and <codeEntityReference>T:Newtonsoft.Json.JsonValidatingReader</codeEntityReference> classes. It sits under
7
the <codeEntityReference>N:Newtonsoft.Json.Schema</codeEntityReference> namespace.</para>
8
<para>JSON Schema is used to validate the structure and
9
data types of a piece of JSON, similar to XML Schema for XML. Read more about JSON Schema at
11
<linkText>json-schema.org</linkText>
12
<linkUri>http://json-schema.org/</linkUri>
13
<linkTarget>_blank</linkTarget>
14
</externalLink></para>
16
<!-- Optional procedures followed by optional code example but must have
17
at least one procedure or code example -->
19
<title>Validating with JSON Schema</title>
21
<para>The simplest way to check if JSON is valid is to load the JSON into a JObject or JArray and then
22
use the <codeEntityReference>M:Newtonsoft.Json.Schema.Extensions.IsValid(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Schema.JsonSchema)</codeEntityReference>
23
method with the JSON Schema.</para>
25
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonSchemaTests.cs" region="IsValidBasic" title="Validate JSON with IsValid" />
27
<para>To get validation error messages use the
28
<codeEntityReference>M:Newtonsoft.Json.Schema.Extensions.IsValid(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Schema.JsonSchema,System.Collections.Generic.IList{System.String}@)</codeEntityReference>
30
<codeEntityReference>M:Newtonsoft.Json.Schema.Extensions.Validate(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Schema.JsonSchema,Newtonsoft.Json.Schema.ValidationEventHandler)</codeEntityReference>
33
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonSchemaTests.cs" region="IsValidMessages" title="Validate JSON with IsValid" />
35
<para>Internally IsValid uses <codeEntityReference>T:Newtonsoft.Json.JsonValidatingReader</codeEntityReference>
36
to perform the JSON Schema validation. To skip the overhead of loading JSON into a JObject/JArray, validating
37
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.</para>
39
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonSchemaTests.cs" region="JsonValidatingReader" title="Validate JSON with JsonValidatingReader" />
45
<title>Creating JSON Schemas</title>
48
<para>The simplest way to get a <codeEntityReference>T:Newtonsoft.Json.Schema.JsonSchema</codeEntityReference> object is to load it from a string or a file.</para>
49
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonSchemaTests.cs" region="LoadJsonSchema" title="Creating JSON Schemas from strings or files" />
51
<para>It is also possible to create JsonSchema objects in code.</para>
52
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonSchemaTests.cs" region="ManuallyCreateJsonSchema" title="Create new JSON Schemas in code" />
57
<codeEntityReference>T:Newtonsoft.Json.Schema.JsonSchema</codeEntityReference>
58
<codeEntityReference>T:Newtonsoft.Json.JsonValidatingReader</codeEntityReference>
61
</developerConceptualDocument>
b'\\ No newline at end of file'