You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/blog/posts/applicability-json-schema-fundamentals-part-1.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,16 +30,16 @@ The validation process for JSON Schema begins with applying the whole JSON Schem
30
30
31
31
A JSON Schema may be a Boolean or an Object. In the introductory article mentioned above, we noted how a Boolean Schema of `true` or `false` resulted in the same assertion result (true and false respectivly) regardless of the instance data. We also noted how the equivalent Object Schemas were `{ }` and `{ "not": { } }` respectively. (The `not` keyword inverts the assertion result.)
<p>An "assertion" is a statement of fact. This is used in reference to the result of testing in Computing. The test might be called "X is 1". If the test passes, the assertion is true!</p>
36
-
</div>
36
+
</AdditionalInfoDiv>
37
37
38
38
When we talk about the whole Schema in terms of application, we usually refer to it as the "root Schema". This is because the other Schemas which are applied to specific instance locations are different, and we call them "subschemas". Differentiating between the root Schema and subschemas allows us to communicate with clarity which JSON Schema we're talking about, and when to use the Schema as part of the validation process.
<p>The following examples assume to be using JSON Schema 2020-12. Where there are things you should know about previous versions (or drafts) of JSON Schema, it will be highlighted.</p>
42
-
</div>
42
+
</AdditionalInfoDiv>
43
43
44
44
45
45
# Subschema application - Validating Objects and Arrays
@@ -134,9 +134,9 @@ Luckily, picking this up with our Schema is simple. The `additionalProperties` k
134
134
135
135
The value of `additionalProperties` is not just a Boolean, but a Schema. This subschema value is applied to all values of the instance object that are not defined in the `properties` object in our example. You could use `additionalProperties` to allow additional properties, but constrain their values to be a String.
<p>There is a little simplification here to help us understand the concept we're looking to learn. If you want to dig a little deeper, check out our <ahref="https://json-schema.org/understanding-json-schema/reference/object.html#additional-properties"target="_blank">learning resources on `additionalProperties`</a>.</p>
139
-
</div>
139
+
</AdditionalInfoDiv>
140
140
141
141
Finally, what if we expect an Object, but are given an Array or another non-object type?
142
142
@@ -177,9 +177,9 @@ Note, `type` takes an Array of types. It may be that your instance is allowed to
<p>In this introduction, we're only going to be covering how things work for JSON Schema 2020-12. If you're using a previous version, including "draft-7" or prior, you will likely benefit from digging a little deeper into the <ahref="https://json-schema.org/understanding-json-schema/reference/array.html"target="_blank">learning resources for Array validation.</a></p>
182
-
</div>
182
+
</AdditionalInfoDiv>
183
183
184
184
Let's step back to our previous example data, where we were provided with an Array as opposed to an Object. Let's say our data is now only allowed to be an Array.
185
185
@@ -231,9 +231,9 @@ This sounds simple, but let's look at some examples.
<p><spanclassName="font-bold">Remember:</span> A Boolean is a valid schema that always produces the assertion result of its value, regardless of the instance data.</p>
236
-
</div>
236
+
</AdditionalInfoDiv>
237
237
238
238
Our first "allOf" example shows the array having three subschemas, which are all `true`. The results are combined using the boolean logic AND operator. The resulting assertion from the `allOf` keyword is `true`.
0 commit comments