How can a quote travel inside quoted text?
03Separate the written spelling, numbered character pieces, recovered text and network bytes.
The outer quotes mark where the text starts and ends. The inner character must not accidentally close it.
We want this inside the text
The character is content, not an instruction to close the outer quotes.
What happens if you change this?
Make one change, then watch again. Restart restores the original example.
Use UTF-8 and omit a leading byte-order mark in transmitted JSON.
Key idea: The written escape and the recovered text are different layers. Compare the recovered values, and keep two-piece character numbers together.
Terms
- JSON
- JavaScript Object Notation: shared rules for writing data as text. Apps in many languages use it.
- Object
- A group of named values, like drawers with different labels.
- Array
- A list whose values have meaningful positions.
- String
- A text value between quotation marks.
- Grammar
- Rules for which marks and words may appear and where.
- Interoperability
- Different apps can read the same data and agree about its meaning.
- Escape
- A backslash instruction inside JSON text that represents a character without ending the quoted string.
- Surrogate pair
- Two numbered UTF-16 pieces used together for one character number. Neither is a separate half-picture.
Rules & examples
Read escapes before comparing values, and keep two-piece character numbers together.
- Quotation marks, reverse solidus, and control characters U+0000–U+001F must be escaped inside strings.
- Escapes such as \u005C represent Unicode code units; non-BMP characters can use a UTF-16 surrogate pair. Unpaired surrogates harm interoperability.
- JSON exchanged outside a closed ecosystem must use UTF-8. Do not add a byte-order mark to network-transmitted JSON.
Different escape spellings can represent the same string. Compare decoded code-unit sequences, rather than raw escape text. A parser may ignore a received BOM for interoperability.
RFC 8259 §§7–8: escape quote, backslash and U+0000–U+001F. Decode before code-unit comparison. A \u escape names one 16-bit code unit; two form a surrogate pair for a non-BMP code point. Grammar can admit unpaired surrogates; §8.2 warns of unpredictable behavior. Outside a closed ecosystem UTF-8 is required. Senders MUST NOT prepend BOM; parsers MAY ignore a received BOM.
Sources
New to this? Start hereA quick picture + helpful background
First, agree how to read the message.
An encoding tells a reader how to interpret bytes. A format tells it how values fit together. Correctly reading a value does not make that value trustworthy.
Helpful first, if these ideas are unfamiliar
These pictures are analogies to help you learn. The linked RFC explains the actual rules.
Related RFCs and changes
“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.
RFC 8259 requires UTF-8 for JSON exchanged between systems outside a closed ecosystem. Earlier JSON specifications did not require a single encoding.
Read the updated RFC section ↗