Media: string-encoding non-JSON data¶
JSON schema has a set of keywords to describe and optionally validate non-JSON data stored inside JSON strings. Since it would be difficult to write validators for many media types, JSON schema validators are not required to validate the contents of JSON strings based on these keywords. However, these keywords are still useful for an application that consumes validated JSON.
contentMediaType¶
The contentMediaType
keyword specifies the MIME type of the contents
of a string, as described in RFC 2046.
There is a list of MIME types officially registered by the IANA,
but the set of types supported will be application and operating system dependent.
Mozilla Developer Network also maintains a shorter list of MIME types that are important for the web
contentEncoding¶
The contentEncoding
keyword specifies the encoding used to store the
contents, as specified in RFC 2054, part
6.1 and RFC
4648.
The acceptable values are 7bit
, 8bit
, binary
, quoted-printable
,
base16
, base32
, and base64
. If not specified, the encoding is the
same as the containing JSON document.
Without getting into the low-level details of each of these encodings, there are really only two options useful for modern usage:
- If the content is encoded in the same encoding as the enclosing JSON
document (which for practical purposes, is almost always UTF-8),
leave
contentEncoding
unspecified, and include the content in a string as-is. This includes text-based content types, such astext/html
orapplication/xml
. - If the content is binary data, set
contentEncoding
tobase64
and encode the contents using Base64. This would include many image types, such asimage/png
or audio types, such asaudio/mpeg
.
contentSchema¶
Documentation Coming soon
Examples¶
The following schema indicates the string contains an HTML document, encoded using the same encoding as the surrounding document:
The following schema indicates that a string contains a PNG image, encoded using Base64: