contentMediaType : String

contentMediaType

String

This keyword declares the media type of the string instance.

Kind Annotation
Applies To String
Dialect 2020-12
Introduced In Draft 7
Vocabulary Content
Specification https://json-schema.org/draft/2020-12/json-schema-validation.html#section-8.4
Metaschema https://json-schema.org/draft/2020-12/meta/content
Also see

Annotations

This keyword produces the content media type as the annotation value.

Explanation

The contentMediaType keyword in JSON Schema specifies the MIME type of the contents of a string. It is used to annotate the type of media contained within a string. It should be noted that:

  • This keyword is purely an annotation and does not directly affect validation.
  • It describes the media type of the binary string after it has been decoded as specified in contentEncoding.
  • It is recommended to set contentEncoding if contentMediaType is declared.
  • The value assigned to contentMediaType must be a valid IANA media type as described in RFC 2046.
  • The list of all registered IANA media types can be found at here.

Examples

Schema with 'contentMediaType' and 'contentEncoding' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "contentEncoding": "base64",
  "contentMediaType": "application/json"
}
An instance with a properly stringified JSON document encoded in base64 is valid Instance
"eyAibmFtZSI6ICJKb2huIERvZSIgfQ=="    // --> { "name": "John Doe" }
An encoded value that represents invalid JSON data is still valid Instance
"eyAibmFtZSI6IH0="    // --> { "name": }
A non-string instance is ignored Instance
true
Annotations
[
  // ...
  {
    "valid": true,
    "keywordLocation": "/contentEncoding",
    "instanceLocation": "",
    "annotation": "base64"
  },
  {
    "valid": true,
    "keywordLocation": "/contentMediaType",
    "instanceLocation": "",
    "annotation": "application/json"
  },
  // ...
]