JavaScript Object Notation (JSON) Text Sequences
Extracted elements (17)
No end-of-sequence indicator is defined. The format is intended for open-ended or indeterminate-length streams, so any termination signal is left to the transport layer rather than the format itself.
Objects, arrays, and strings are self-delimited in JSON and need no special truncation detection. Numbers and the literals true, false, and null are not self-delimited and require the trailing LF 'canary' octet (0x0A) to distinguish a complete value from a truncated one (e.g., '123' could be a truncated '1234').
RS (0x1E) was chosen as the delimiter because it is an ASCII control character that may only appear in JSON strings in escaped form, making it unambiguous as a sequence element start delimiter without requiring a streaming parser. LF was added after each element specifically to detect truncation of top-level non-self-delimited values (numbers, true, false, null).
Multiple consecutive RS octets do not denote empty sequence elements between them and can be ignored by parsers. This permits lenient recovery when truncated elements leave residual RS bytes.
The format does not define a mechanism for reliably identifying sequence elements by position. When truncation is possible, intended elements may be missing entirely, making nth-element references unreliable.
When a JSON text sequence encoder accepts already-encoded JSON texts (rather than encoding them itself), it ought to parse them before adding them to a sequence to ensure they are properly formed. Truncation detection for non-self-delimited values is only reliable when the encoder controls the encoding of individual texts.
If parsing an octet string as a UTF-8-encoded JSON text fails, the parser SHOULD nonetheless continue parsing the remainder of the sequence. The parser can report such failures to applications, which might then choose to terminate parsing.
JSON text sequences MUST use UTF-8 encoding. Other encodings of JSON (UTF-16 and UTF-32) MUST NOT be used.
Parsers MUST check that any JSON texts that are a top-level number, or that might be 'true', 'false', or 'null', include JSON whitespace (at least one byte matching the 'ws' ABNF rule from RFC 7159) after that value; otherwise the JSON text may have been truncated.
Parsers MUST drop JSON text sequence elements consisting of non-self-delimited top-level values (numbers, true, false, null) that may have been truncated, i.e., those not followed by whitespace. Parsers can optionally report such texts as warnings.
A JSON text sequence consists of any number of JSON texts, each encoded in UTF-8, each prefixed by an ASCII Record Separator (RS, 0x1E), and each followed by a Line Feed (LF, 0x0A). The format uses two distinct ABNF grammars: one for parsers (tolerating truncation) and one for encoders (assuming complete elements).
This document registers the MIME media type 'application/json-seq' for JSON text sequences. Required parameters: none. Optional parameters: none. Encoding considerations: binary. Change controller: IETF.
Incremental JSON text parsers and non-incremental parsers may disagree on what constitutes a valid sequence element. For example, '<RS>"foo"<LF>456<LF><RS>' may be parsed as one element by an incremental parser and as empty by a non-incremental parser. This disagreement can be exploited to smuggle data past sequence parsers that do not warn on JSON text failures.
Parsers must operate on input assumed to be untrusted and must fail gracefully in the face of malicious inputs. All security considerations of JSON (RFC 7159) apply to this format.
Repeated parsing and re-encoding of a JSON text sequence can result in addition or stripping of trailing LF bytes from sequence elements, breaking signature validation. JSON has no canonical form, so neither does the JSON text sequence format; cryptographic integrity protection is not provided.
The encoder ABNF defines a JSON-sequence as zero or more repetitions of RS (0x1E), a JSON-text (UTF-8 per RFC 7159), and LF (0x0A). Each element is thus bookended by RS at the start and LF at the end.
The parser ABNF defines an input-JSON-sequence as zero or more occurrences of one or more RS bytes (0x1E) followed by a possible-JSON string (any octets other than RS). Each such octet string is then interpreted as a UTF-8-encoded JSON text.