Files
json/docs/mkdocs/docs/api/json_sax/index.md
T
Niels Lohmann 52b72b5684 Improve documentation: byte layouts, release pages, See also, dark-mode images (#5906)
- Make the iterator range illustrations legible in dark mode (prefers-color-scheme
  rules inside the SVGs).
- Add a "Byte layout" section with a color-coded byte table to each binary format
  page (BJData, BON8, BSON, CBOR, MessagePack, UBJSON), and highlight the smallest
  size per file in the comparison table.
- Add "See also" sections to the overview pages that lacked one.
- Split the release notes into one page per release, grouped by minor version on
  the overview page, with an "API changes" section per release generated from the
  API pages' version histories (hooks/api_changes.py).
- Fact-check the release notes and version histories against the release tags and
  correct wrong or misleading entries (e.g., json_serializer 2.1.0, merge_patch
  3.1.0, items, count, operator[], to_bjdata, std::string_view key support).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-24 17:57:44 +02:00

3.1 KiB

nlohmann::json_sax

template<typename BasicJsonType>
struct json_sax;

This class describes the SAX interface used by sax_parse. Each function is called in different situations while the input is parsed. The boolean return value informs the parser whether to continue processing the input.

For instance, parsing the JSON text {"a": [1, true]} triggers the following callbacks, in order:

sequenceDiagram
    participant P as Parser
    participant H as SAX handler

    P->>H: start_object(elements)
    P->>H: key("a")
    P->>H: start_array(elements)
    P->>H: number_unsigned(1)
    P->>H: boolean(true)
    P->>H: end_array()
    P->>H: end_object()

Note elements is passed as #!cpp std::numeric_limits<std::size_t>::max() (i.e., "unknown") for JSON text input; only binary formats such as CBOR or MessagePack may report the actual number of elements in start_object/ start_array. Also note that 1 is reported via number_unsigned rather than number_integer because it has no leading - sign.

Template parameters

BasicJsonType
a specialization of basic_json

Member types

Member functions

  • binary (virtual) - a binary value was read
  • boolean (virtual) - a boolean value was read
  • end_array (virtual) - the end of an array was read
  • end_object (virtual) - the end of an object was read
  • key (virtual) - an object key was read
  • null (virtual) - a null value was read
  • number_float (virtual) - a floating-point number was read
  • number_integer (virtual) - an integer number was read
  • number_unsigned (virtual) - an unsigned integer number was read
  • parse_error (virtual) - a parse error occurred
  • start_array (virtual) - the beginning of an array was read
  • start_object (virtual) - the beginning of an object was read
  • string (virtual) - a string value was read

See also

Version history

  • Added in version 3.2.0.
  • Support for binary values (binary_t, binary) added in version 3.8.0.