contentMediaType : String
contentMediaType
StringThis 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
ifcontentMediaType
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": "https://json-schema.org/draft/2020-12/schema",
"contentEncoding": "base64",
"contentMediaType": "application/json"
}
"eyAibmFtZSI6ICJKb2huIERvZSIgfQ==" // --> { "name": "John Doe" }
"eyAibmFtZSI6IH0=" // --> { "name": }
true
[
// ...
{
"valid": true,
"keywordLocation": "/contentEncoding",
"instanceLocation": "",
"annotation": "base64"
},
{
"valid": true,
"keywordLocation": "/contentMediaType",
"instanceLocation": "",
"annotation": "application/json"
},
// ...
]