Detect possibly truncated scalars
04Numbers, true, false and null need trailing JSON whitespace so a parser can reject potentially truncated values.
A trailing LF cannot turn truefalse into one valid JSON text.
Source for this drawing: RFC 7464 · Read RFC section 2.4 ↗
New to this? Start hereA quick picture + helpful background
A message needs an address.
Think of a packet as a small addressed envelope. Devices pass it onward; transport protocols decide what delivery promises an application gets.
Helpful first, if these ideas are unfamiliar
These pictures are analogies to help you learn. The linked RFC explains the actual rules.
Terms in this drawing
- Canary byte
- A trailing byte whose absence can signal possible truncation.
- Self-delimited
- A value whose closing syntax identifies its end, such as a closing quote or brace.
Related RFCs and changes
“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.
Require a whitespace canary for non-self-delimited values.
- Parsers MUST check that a top-level number, or text that might be true, false or null, has at least one JSON whitespace byte after that value. The encoder’s LF satisfies this check.
- Parsers MUST drop non-self-delimited top-level elements that lack that whitespace and may have been truncated. For example, RS 123 RS might be a truncated 1234; a boundary alone is insufficient.
- Whitespace does not repair invalid JSON: truefalse is not two values and is not a valid JSON text. Objects, arrays and strings are self-delimited; incremental parsers may produce these without consuming another byte. Detecting truncation still depends on encoders receiving or producing complete JSON texts.
Three independent comparisons are shown, not consecutive requests: 123 without trailing whitespace is dropped; 123 followed by LF passes this check and parses; truefalse followed by LF still fails JSON parsing. The acceptance example is a format-level result, not authentication or a promise of intact transport.
Read the RFC section ↗