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
Hint: Use the jsonschema metaschema command to catch keywords set to invalid values
|
---|---|
Kind | Annotation |
Applies To | String |
Base 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
Hint: Use the jsonschema validate command to collect annotations from the command-line
|
Affected By |
|
Affects | None |
Also See |
|
When the contentMediaType
keyword is set to a media type that adheres to the JSON data model (like JSON
itself, YAML or UBJSON), the
contentSchema
keyword declares the schema that describes the corresponding
string instance value after decoding it. This keyword does not affect
validation, but the evaluator will collect its value as an annotation.
Common Pitfall
The JSON Schema specification prohibits implementations, for security reasons, from automatically attempting to decode, parse, or validate encoded data without the consumer explicitly opting in to such behaviour. If you require this feature, consult the documentation of your tooling of choice to see if it supports content encoding/decoding and how to enable it.
Remember that JSON Schema is a constraint-driven language.
Therefore, non-string instances successfully validate against this
keyword. If needed, make use of the type
keyword to constraint
the accepted type accordingly.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contentMediaType": "application/json",
"contentEncoding": "base64",
"contentSchema": { "type": "object" }
}
"eyAibmFtZSI6ICJKb2huIERvZSIgfQ==" // { "name": "John Doe" }
{ "keyword": "/contentMediaType", "instance": "", "value": "application/json" }
{ "keyword": "/contentEncoding", "instance": "", "value": "base64" }
{ "keyword": "/contentSchema", "instance": "", "value": { "type": "object" } }
"eyAibmFtZSI6IH0=" // { "name": }
{ "keyword": "/contentMediaType", "instance": "", "value": "application/json" }
{ "keyword": "/contentEncoding", "instance": "", "value": "base64" }
{ "keyword": "/contentSchema", "instance": "", "value": { "type": "object" } }
"MTIzNA==" // 1234
{ "keyword": "/contentMediaType", "instance": "", "value": "application/json" }
{ "keyword": "/contentEncoding", "instance": "", "value": "base64" }
{ "keyword": "/contentSchema", "instance": "", "value": { "type": "object" } }
1234