contentSchema : Schema

contentSchema

Schema

This 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.

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

A schema that describes JSON object values encoded using Base 64 Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "contentMediaType": "application/json",
  "contentEncoding": "base64",
  "contentSchema": { "type": "object" }
}
Valid A string value that represents a valid JSON object encoded in Base 64 is valid and an annotations are emitted Instance
"eyAibmFtZSI6ICJKb2huIERvZSIgfQ==" // { "name": "John Doe" }
Annotations
{ "keyword": "/contentMediaType", "instance": "", "value": "application/json" }
{ "keyword": "/contentEncoding", "instance": "", "value": "base64" }
{ "keyword": "/contentSchema", "instance": "", "value": { "type": "object" } }
Valid A string value that represents an invalid JSON object encoded in Base 64 is valid and an annotations are still emitted Instance
"eyAibmFtZSI6IH0=" // { "name": }
Annotations
{ "keyword": "/contentMediaType", "instance": "", "value": "application/json" }
{ "keyword": "/contentEncoding", "instance": "", "value": "base64" }
{ "keyword": "/contentSchema", "instance": "", "value": { "type": "object" } }
Valid A string value that represents a valid JSON number encoded in Base 64 is valid and an annotations are still emitted Instance
"MTIzNA==" // 1234
Annotations
{ "keyword": "/contentMediaType", "instance": "", "value": "application/json" }
{ "keyword": "/contentEncoding", "instance": "", "value": "base64" }
{ "keyword": "/contentSchema", "instance": "", "value": { "type": "object" } }
Valid A non-string value is valid but no annotations are emitted Instance
1234