Visual RFC.
ALL RFCs / RFC 8259
Read the RFC ↗
RFC 8259 / JSON BUILDING BLOCKS

How can a quote travel inside quoted text?

03

Separate the written spelling, numbered character pieces, recovered text and network bytes.

RFC 8259 · § 7EXAMPLE
1 / 4 · The quote inside the text is data

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.

3 / 3
03
Encode interoperable network text.

Use UTF-8 and omit a leading byte-order mark in transmitted JSON.

How can a quote travel inside quoted text?Two different JSON string spellings decode to the same characters, then a UTF-8 byte strip shows an interoperable network representation.Escaped spelling and string value differIllustrative reverse-solidus character"a\\b""a\u005Cb"a + U+005C + bSame decoded code-unit sequence22615C5C6222UTF-8 bytes of the first JSON text · no BOMTransmit the JSON text in UTF-8 without a BOM

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.

Look up a term in the glossary ↗

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
Protocol participantThreat or exceptionProtocol controlSimplified drawings · precise section references
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.

What changed
RFC 7159 character-encoding guidanceRFC 8259 §8.1

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 ↗

All chapters in RFC 8259

Drawing view

Scroll the drawing to see every part. Playback controls stay above it.

RFC 9700 / CHAPTERS

Chapters

For full details, tables, algorithms, and exceptions, read the original RFC.

RFC status and corrections ↗