contentSchema : Schema
contentSchema
SchemaThis keyword declares a schema which describes the structure of the string.
Value | This keyword must be set to a valid JSON Schema |
---|---|
Kind | Annotation |
Applies To | String |
Dialect | 2020-12 |
Changed In | None |
Introduced In | 2019-09 |
Vocabulary | Content |
Specification | https://json-schema.org/draft/2020-12/json-schema-validation.html#section-8.5 |
Metaschema | https://json-schema.org/draft/2020-12/meta/content |
Official Tests | draft2020-12/content.json |
Default |
{}
|
Annotation | Object Boolean The content schema set by this keyword |
Affected By |
|
Affects | None |
Also See |
|
The contentSchema
keyword allows you to specify a schema that describes the structure of the content within a string instance, particularly when used in conjunction with the contentMediaType
keyword. This is useful when the string instance contains data conforming to the JSON data model.
However, it’s important to note that contentSchema
is merely an annotation and is not directly involved in the validation process. Instead, applications that consume JSON Schemas must use this information as they see fit. contentSchema
must be a valid JSON Schema, but it is ignored if contentMediaType
is absent.
Applications utilizing JSON Schemas are expected to use the provided contentSchema
to validate content if applicable. If a schema is provided but does not match the content structure, it should be considered an error.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contentMediaType": "application/json",
"contentEncoding": "base64",
"contentSchema": { "type": "object" }
}
"eyAibmFtZSI6ICJKb2huIERvZSIgfQ==" // --> { "name": "John Doe" }
"eyAibmFtZSI6IH0=" // --> { "name": }
true
{ "keyword": "/contentMediaType", "instance": "", "value": "application/json" }
{ "keyword": "/contentEncoding", "instance": "", "value": "base64" }
{ "keyword": "/contentSchema", "instance": "", "value": { "type": "object" } }