Visual RFC.
ALL RFCs / RFC 8259
Read the RFC ↗
RFC 8259 / INTEROPERABLE EXCHANGE

Parsing and generating

05

A parser builds an internal representation from text. A generator must produce text that strictly follows JSON grammar.

Related RFCs and changes

“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.

DIAGRAM§ 9 ↗
RFC 8259 · § 9EXAMPLE
3 / 3
Parsing and generatingJSON tokens become a value tree, and a generator emits strict JSON with quoted member names, separating parsing from source-code execution.Parse data, then generate strict JSONIllustrative object with one member{"count": 3}parseobject"count" → 3value treegenerate{"count":3}Strict output · no eval · apply application validationGenerate text that follows JSON grammar strictly
03
Serialize back to conforming text.

Output uses quoted member names and valid separators, even if the input parser tolerated extensions.

Protocol participantThreat or exceptionProtocol controlSimplified drawings · precise section references
KEY POINT

Treat input as data and generate strict syntax.

  • A parser must accept conforming JSON texts, subject to the permitted implementation limits on size, depth, strings, and numbers.
  • A parser may accept extensions, but generators must emit text that strictly conforms to JSON grammar.
  • Do not use eval or an equivalent source-code execution mechanism to parse untrusted JSON.
DETAILS

Successful syntax parsing is separate from application schema validation, authorization, and safe use of values. Put practical input limits around untrusted data.

Read the RFC section ↗

Diagrams simplify the RFC. Read the linked sections for complete requirements.

Privacy
All chapters in this RFC
  1. A tree of JSON values
  2. Objects and arrays
  3. Strings and Unicode
  4. Numbers and precision
  5. Parsing and generating
  6. Interoperability checks
RFC 9700 / CHAPTERS

Chapters

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

RFC status and corrections ↗