mirror of
https://github.com/nlohmann/json.git
synced 2026-11-03 11:25:33 +00:00
docs: new design for the documentation site (#5934)
* 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>
This commit is contained in:
1 parent
2bb2feeef4
commit
a47170346a
417 files changed
+11100
-3041
No files matched your search
@@ -29,6 +29,8 @@ class sax_t ["json::sax_t"] {
|
||||
}
|
||||
```
|
||||
|
||||
<p class="nj-caption" markdown>The interface `json::sax_t`: one function per event, each returning `bool`; the functions marked with `*` are pure virtual.</p>
|
||||
|
||||
```cpp
|
||||
// called when null is parsed
|
||||
bool null();
|
||||
@@ -62,6 +64,34 @@ bool parse_error(std::size_t position, const std::string& last_token, const json
|
||||
|
||||
The return value of each function determines whether parsing should proceed.
|
||||
|
||||
## Stepping through the events
|
||||
|
||||
The events for a small input, step by step, and what two different handlers do with them. Press *Play* or step with *Next*:
|
||||
|
||||
<div class="nj-sax nj-fig" id="sax-event-stepper" data-nj-sax role="group" aria-label="SAX events for the input {"a":[1,true],"b":"x"}, and the state of a handler after each event">
|
||||
<div class="nj-sax__lane nj-sax__lane--text"><p class="nj-sax__h">input</p><p class="nj-sax__text"><code class="nj-sax__src">{"a":[1,true],"b":"x"}</code></p></div>
|
||||
<div class="nj-sax__lane nj-sax__lane--events"><p class="nj-sax__h">events, in the order the parser calls them</p><ol class="nj-sax__events">
|
||||
<li class="nj-sax-ev nj-sax-ev--os"><code>start_object(-1)</code></li>
|
||||
<li class="nj-sax-ev nj-sax-ev--k"><code>key("a")</code></li>
|
||||
<li class="nj-sax-ev nj-sax-ev--as"><code>start_array(-1)</code></li>
|
||||
<li class="nj-sax-ev nj-sax-ev--v"><code>number_unsigned(1)</code></li>
|
||||
<li class="nj-sax-ev nj-sax-ev--v"><code>boolean(true)</code></li>
|
||||
<li class="nj-sax-ev nj-sax-ev--ae"><code>end_array()</code></li>
|
||||
<li class="nj-sax-ev nj-sax-ev--k"><code>key("b")</code></li>
|
||||
<li class="nj-sax-ev nj-sax-ev--v"><code>string("x")</code></li>
|
||||
<li class="nj-sax-ev nj-sax-ev--oe"><code>end_object()</code></li>
|
||||
</ol></div>
|
||||
<div class="nj-sax__lane nj-sax__lane--state"><p class="nj-sax__h">handler: build a value tree, as <code>parse</code> does</p><div class="nj-sax__state"><pre class="nj-sax__tree"><code>{
|
||||
"a": [
|
||||
1,
|
||||
true
|
||||
],
|
||||
"b": "x"
|
||||
}</code></pre><p class="nj-sax__note">After <code>end_object()</code> the tree is complete and no container is open. The number of elements is passed as -1: the parser does not know it in advance.</p></div></div>
|
||||
</div>
|
||||
|
||||
<p class="nj-caption" markdown>The three lanes show the input consumed so far, the events called so far, and the state of the selected handler (*build a tree* or *keep only /b*). Check *return false at this event* to stop the parse at the current event and see which events are no longer called.</p>
|
||||
|
||||
To implement your own SAX handler, proceed as follows:
|
||||
|
||||
1. Implement the SAX interface in a class. You can use class `nlohmann::json_sax<json>` as base class, but you can also use any class where the functions described above are implemented and public.
|
||||
@@ -72,5 +102,9 @@ Note the `sax_parse` function only returns a `#!cpp bool` indicating the result
|
||||
|
||||
## See also
|
||||
|
||||
- [json_sax](../../api/json_sax/index.md) - documentation of the SAX interface
|
||||
- [sax_parse](../../api/basic_json/sax_parse.md) - SAX parser
|
||||
- [`json_sax`](../../api/json_sax/index.md) - documentation of the SAX interface
|
||||
- [`sax_parse`](../../api/basic_json/sax_parse.md) - SAX parser
|
||||
- [Parsing](index.md) - overview of the parsing functions
|
||||
- [Parsing and Exceptions](parse_exceptions.md) - handling parse errors and locating them in the input
|
||||
- [`parse`](../../api/basic_json/parse.md) - deserialize from a compatible input
|
||||
- [Binary Formats](../binary_formats/index.md) - CBOR, MessagePack, BSON, and other formats
|
||||
Reference in new issue
Block a user