* docs: new design for the documentation site Apply the brand to the Material for MkDocs site: Inter and JetBrains Mono served by the site (upright and real italic), brand colours, blue header band with the syntax pattern, wordmark in the header, new home page (hero, cards, animated feature tour), 404 page, polish for tabs, search, footer, focus rings, tables and code blocks, and theme features (code copy, previous/next footer, TOC follow, search suggestions). Draw the number railroad diagram, the parser callback events and the iterator illustrations as inline SVGs that follow the light and dark scheme. The generator scripts are in docs/mkdocs/scripts/figures; the feature slideshow (json-light.svg, json-dark.svg, replacing json.gif on the home page) is built by docs/mkdocs/scripts/slideshow. Decision nodes in five flowcharts become hexagons, which need far less room. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * docs: add figures, table captions and a macro chooser - Figures with numbered captions: SAX stepper, json_view layout and edit stepper, exception map, JSON pointer and patch walkers, QA pipeline, scaling and binary size charts, roadmap lanes, release timeline, integration decision tree and namespace builder - Table captions (nj-table-caption) on 9 pages - Compile times: modules and PCH charts, filesystem section, re-measured Figure 1, links between features/modules.md and compile_times.md - Interactive macro chooser for features/arbitrary_types.md - Link check: exclude URLs that answer the plugin with 400/401/419 or are dead (customers.md) Signed-off-by: Niels Lohmann <mail@nlohmann.me> * docs: macro chooser generates adl_serializer for non-default-constructible types Signed-off-by: Niels Lohmann <mail@nlohmann.me> * docs: cross-link concept pages and API pages in See also sections Add See also links in both directions between the concept pages (features, home, integration) and the API pages, write API links in code font, give every entry a comment after a dash, and show the callback event figure on the parser callbacks page. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * docs: address review comments on the new design - Home: add a "Latest release" button - Sponsors: update the list and group it by tier - Features: list all feature pages on the index page - Releases: add highlights per release, link the 4.0 roadmap, add the first commit to the timeline - Exceptions: prefix all example messages with the exception name - API: no code font for format names in the See also links of the to_/from_ pages - Merge Patch: show the document before, the patch, and the result - Replace "--" with typographic dashes, mark external links with an icon, center Mermaid diagrams Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me>
3.3 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()
Each arrow is one call from the parser to the SAX handler, from top to bottom in the order the calls happen.
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
- number_integer_t -
BasicJsonType's type for numbers (integer) - number_unsigned_t -
BasicJsonType's type for numbers (unsigned) - number_float_t -
BasicJsonType's type for numbers (floating-point) - string_t -
BasicJsonType's type for strings - binary_t -
BasicJsonType's type for binary arrays
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
- SAX interface - guide to event-based parsing
sax_parse- generate SAX events from an inputparse- DOM parsing, with optional parser callbacks- Parse exceptions - how parse errors are reported
Version history
- Added in version 3.2.0.
- Support for binary values (
binary_t,binary) added in version 3.8.0.