You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Modify non_json_data.md, document contentSchema keyword
* Update pages/understanding-json-schema/reference/non_json_data.md
Co-authored-by: Jason Desrosiers <[email protected]>
* Integrate review comments to non_json_data.md
This version includes changes suggested by Jason, Benjamin, Blessing, and Anitha
* Improve heading structure of non_json_data.md
These changes introduce a better heading structure for scannability
---------
Co-authored-by: Jason Desrosiers <[email protected]>
<Keywordslabel="single: non-JSON data single: media"/>
6
+
<Keywordslabel="single: non-JSON data single: media"/>
7
7
8
8
<Starlabel="New in draft 7" />
9
9
10
-
JSON schema has a set of [keywords](../../learn/glossary#keyword) to describe and optionally validate
11
-
non-JSON data stored inside JSON strings. Since it would be difficult to
12
-
write validators for many media types, JSON schema validators are not
13
-
required to validate the contents of JSON strings based on these
14
-
keywords. However, these keywords are still useful for an application
15
-
that consumes validated JSON.
10
+
JSON schema has a set of [keywords](../../learn/glossary#keyword) to describe and optionally validate non-JSON data stored inside JSON strings. Due to the difficulty in writing validators for all media types, JSON schema validators are not required to validate the contents of JSON strings based on these keywords. However, applications that consume validated JSON use these keywords to encode and decode data during the storage and transmission of media types.
The `contentMediaType` keyword specifies the MIME type of the contents
22
-
of a string, as described in [RFC 2046](https://tools.ietf.org/html/rfc2046).
23
-
There is a list of [MIME types officially registered by the IANA](http://www.iana.org/assignments/media-types/media-types.xhtml),
24
-
but the set of types supported will be application and operating system dependent.
25
-
Mozilla Developer Network also maintains a [shorter list of MIME types that are important for the web](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types)
16
+
The `contentMediaType` keyword specifies the media type of the content of a string, as described in [RFC 2046](https://tools.ietf.org/html/rfc2046). The Internet Assigned Numbers Authority (IANA) has officially registered [a comprehensive list of media types](http://www.iana.org/assignments/media-types/media-types.xhtml), but the set of supported types depends on the application and operating system. Mozilla Developer Network maintains a [shorter list of media types that are important for the web](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types)
`base16`, `base32`, and `base64`. If not specified, the encoding is the
38
-
same as the containing JSON document.
39
36
40
-
Without getting into the low-level details of each of these encodings,
41
-
there are really only two options useful for modern usage:
37
+
The `contentEncoding` keyword specifies the encoding used to store the contents, as specified in [RFC 2054, part 6.1](https://tools.ietf.org/html/rfc2045) and [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648).
42
38
43
-
- If the content is encoded in the same encoding as the enclosing JSON
44
-
document (which for practical purposes, is almost always UTF-8),
45
-
leave `contentEncoding` unspecified, and include the content in a
46
-
string as-is. This includes text-based content types, such as
47
-
`text/html` or `application/xml`.
48
-
- If the content is binary data, set `contentEncoding` to `base64` and
49
-
encode the contents using
50
-
[Base64](https://tools.ietf.org/html/rfc4648). This would include
51
-
many image types, such as `image/png` or audio types, such as
52
-
`audio/mpeg`.
39
+
The acceptable values are the following:
40
+
-`quoted-printable`
41
+
-`base16`
42
+
-`base32`
43
+
-`base64`
44
+
45
+
If not specified, the encoding is the same as the containing JSON document.
1.**Same encoding as JSON document**: Leave `contentEncoding` unspecified and include the content in a string as-is. This is suitable for text-based content types (e.g., `text/html`, `application/xml`) and assumes UTF-8 encoding in most cases.
50
+
2.**Binary data**: Set `contentEncoding` to `base64` and encode the content using Base64. This is appropriate for binary content types such as images (`image/png`) or audio files (`audio/mpeg`).
58
51
59
-
Documentation Coming soon
60
52
61
-
##Examples
53
+
### Example
62
54
63
-
The following schema indicates the string contains an HTML document,
64
-
encoded using the same encoding as the surrounding document:
55
+
The following schema indicates that a string contains a PNG file and is encoded using Base64:
1. The sender encodes the content, using `contentEncoding` to specify the encoding method (e.g., base64) and `contentMediaType` to indicate the media type of the original content.
95
+
2. The encoded data is then transmitted.
96
+
3. Upon receiving the data, the consumer application uses the `contentEncoding` and `contentMediaType` information to select the appropriate decoding method.
97
+
4. Finally, the consumer application decodes the data, restoring it to its original form.
98
+
99
+
This process ensures that the non-JSON content is properly encoded for transmission and accurately decoded by the recipient, maintaining the integrity of the data throughout the process.
The value of `contentSchema` must be a valid JSON schema that you can use to define the structure and constraints of the content. It is used in conjunction with `contentMediaType` when the instance is a string. If `contentMediaType` is absent, the value of `contentSchema` is ignored.
107
+
108
+
## Full example
109
+
110
+
The following schema indicates that a string contains a JSON object encoded using Base64:
0 commit comments