rfc-7464

JavaScript Object Notation (JSON) Text Sequences

N. Williams
date2015-02 streamIETF areaapp wgjson statusPROPOSED STANDARD pages8 canonicalhttps://www.rfc-editor.org/rfc/rfc7464 doi10.17487/RFC7464 errataview
This document describes the JavaScript Object Notation (JSON) text sequence format and associated media type "application/json-seq". A JSON text sequence consists of any number of JSON texts, all encoded in UTF-8, each prefixed by an ASCII Record Separator (0x1E), and each ending with an ASCII Line Feed character (0x0A).

Extracted elements (17)

design-rationale §2.1

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.

json

design-rationale §2.4

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').

json

design-rationale §2.2

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).

json

interoperability-note §2.1

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.

json

interoperability-note §2.1

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.

json

interoperability-note §2.2

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.

json

normative-requirement §2.1 SHOULD

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

normative-requirement §2 MUST

JSON text sequences MUST use UTF-8 encoding. Other encodings of JSON (UTF-16 and UTF-32) MUST NOT be used.

json

normative-requirement §2.4 MUST

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.

json

normative-requirement §2.4 MUST

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.

json

protocol-element §2

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).

json

registry §4

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.

json, registry

security-consideration §3

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.

json, security

security-consideration §3

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.

json, security

security-consideration §3

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.

json, security, crypto

wire-format §2.2

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.

json

wire-format §2.1

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.

json