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
Kind Annotation
Applies To String
Dialect 2020-12
Introduced In 2019-09
Vocabulary 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.


Schema with 'contentSchema', 'contentMediaType' and 'contentEncoding' keyword Schema
  "$schema": "",
  "contentMediaType": "application/json",
  "contentEncoding": "base64",
  "contentSchema": { "type": "object" }
Valid An instance with a properly stringified JSON document encoded in base64 is valid Instance
"eyAibmFtZSI6ICJKb2huIERvZSIgfQ=="    // --> { "name": "John Doe" }
Valid An encoded value that represents invalid JSON data is still valid Instance
"eyAibmFtZSI6IH0="    // --> { "name": }
Valid A non-object instance is ignored Instance
{ "keyword": "/contentMediaType", "instance": "", "value": "application/json" }
{ "keyword": "/contentEncoding", "instance": "", "value": "base64" }
{ "keyword": "/contentSchema", "instance": "", "value": { "type": "object" } }