This commit is contained in:
nlohmann committed 2026-10-07 06:52:50 +00:00
1 parent 42b1d75fff
commit 6cba066a3f
9 files changed
+307 -293

No files matched your search

+2 -2
View File
@@ -9,10 +9,10 @@ enum class cbor_tag_handler_t
};
```
This enumeration is used in the [`from_cbor`](from_cbor.md) function to choose how to treat tags:
This enumeration is used in [`from_cbor`](from_cbor.md) and [`sax_parse`](sax_parse.md) to choose how to treat tags:
error
: throw a `parse_error` exception in case of a tag
: report a parse error in case of a tag (the `from_cbor` overloads throw a `parse_error` exception by default)
ignore
: ignore tags
+2 -2
View File
@@ -4,7 +4,7 @@
<span class=w> </span><span class=n>ignore</span><span class=p>,</span>
<span class=w> </span><span class=n>store</span>
<span class=p>};</span>
</code></pre></div> <p>This enumeration is used in the <a href=../from_cbor/ ><code>from_cbor</code></a> function to choose how to treat tags:</p> <dl> <dt>error</dt> <dd>throw a <code>parse_error</code> exception in case of a tag</dd> <dt>ignore</dt> <dd>ignore tags</dd> <dt>store</dt> <dd>store tagged byte strings (for bytes 0xd8..0xdb) as binary values with the tag as subtype; other tagged values are read as if the tag were ignored. If several tags precede a byte string, only the innermost one is stored.</dd> </dl> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example</summary> <p>The example below shows how the different values of the <code>cbor_tag_handler_t</code> influence the behavior of <a href=../from_cbor/ ><code>from_cbor</code></a> when reading a tagged byte string.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span>
</code></pre></div> <p>This enumeration is used in <a href=../from_cbor/ ><code>from_cbor</code></a> and <a href=../sax_parse/ ><code>sax_parse</code></a> to choose how to treat tags:</p> <dl> <dt>error</dt> <dd>report a parse error in case of a tag (the <code>from_cbor</code> overloads throw a <code>parse_error</code> exception by default)</dd> <dt>ignore</dt> <dd>ignore tags</dd> <dt>store</dt> <dd>store tagged byte strings (for bytes 0xd8..0xdb) as binary values with the tag as subtype; other tagged values are read as if the tag were ignored. If several tags precede a byte string, only the innermost one is stored.</dd> </dl> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example</summary> <p>The example below shows how the different values of the <code>cbor_tag_handler_t</code> influence the behavior of <a href=../from_cbor/ ><code>from_cbor</code></a> when reading a tagged byte string.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span>
<span class=k>using</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span>
@@ -35,4 +35,4 @@
</code></pre></div> <p>Output:</p> <div class=highlight><pre><span></span><code><span class=p>[</span><span class=err>jso</span><span class=kc>n</span><span class=err>.excep</span><span class=kc>t</span><span class=err>io</span><span class=kc>n</span><span class=err>.parse_error.</span><span class=mi>112</span><span class=p>]</span><span class=w> </span><span class=err>parse</span><span class=w> </span><span class=err>error</span><span class=w> </span><span class=err>a</span><span class=kc>t</span><span class=w> </span><span class=err>by</span><span class=kc>te</span><span class=w> </span><span class=mi>1</span><span class=p>:</span><span class=w> </span><span class=err>sy</span><span class=kc>nta</span><span class=err>x</span><span class=w> </span><span class=err>error</span><span class=w> </span><span class=err>while</span><span class=w> </span><span class=err>parsi</span><span class=kc>n</span><span class=err>g</span><span class=w> </span><span class=err>CBOR</span><span class=w> </span><span class=err>value</span><span class=p>:</span><span class=w> </span><span class=err>i</span><span class=kc>n</span><span class=err>valid</span><span class=w> </span><span class=err>by</span><span class=kc>te</span><span class=p>:</span><span class=w> </span><span class=mi>0</span><span class=err>xD</span><span class=mi>8</span>
<span class=p>{</span><span class=nt>"bytes"</span><span class=p>:[</span><span class=mi>202</span><span class=p>,</span><span class=mi>254</span><span class=p>,</span><span class=mi>186</span><span class=p>,</span><span class=mi>190</span><span class=p>],</span><span class=nt>"subtype"</span><span class=p>:</span><span class=kc>null</span><span class=p>}</span>
<span class=p>{</span><span class=nt>"bytes"</span><span class=p>:[</span><span class=mi>202</span><span class=p>,</span><span class=mi>254</span><span class=p>,</span><span class=mi>186</span><span class=p>,</span><span class=mi>190</span><span class=p>],</span><span class=nt>"subtype"</span><span class=p>:</span><span class=mi>66</span><span class=p>}</span>
</code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../from_cbor/ >from_cbor</a> deserializes a <abbr title="JavaScript Object Notation">JSON</abbr> value from <abbr title="Concise Binary Object Representation">CBOR</abbr></li> <li><a href=../input_format_t/ >input_format_t</a> the enumeration of supported input formats</li> <li><a href=../../../features/binary_formats/cbor/ ><abbr title="Concise Binary Object Representation">CBOR</abbr></a> - the article on the <abbr title="Concise Binary Object Representation">CBOR</abbr> format</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ul> <li>Added in version 3.9.0. Added value <code>store</code> in 3.10.0.</li> </ul> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 09:32:15 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.1 320h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.Line truncated
</code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../from_cbor/ >from_cbor</a> deserializes a <abbr title="JavaScript Object Notation">JSON</abbr> value from <abbr title="Concise Binary Object Representation">CBOR</abbr></li> <li><a href=../input_format_t/ >input_format_t</a> the enumeration of supported input formats</li> <li><a href=../../../features/binary_formats/cbor/ ><abbr title="Concise Binary Object Representation">CBOR</abbr></a> - the article on the <abbr title="Concise Binary Object Representation">CBOR</abbr> format</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ul> <li>Added in version 3.9.0. Added value <code>store</code> in 3.10.0.</li> </ul> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 7, 2026 05:38:24 UTC">October 7, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.1 320h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.Line truncated
+2 -2
View File
@@ -9,9 +9,9 @@ enum class cbor_tag_handler_t
};
```
This enumeration is used in the [`from_cbor`](https://json.nlohmann.me/api/basic_json/from_cbor/index.md) function to choose how to treat tags:
This enumeration is used in [`from_cbor`](https://json.nlohmann.me/api/basic_json/from_cbor/index.md) and [`sax_parse`](https://json.nlohmann.me/api/basic_json/sax_parse/index.md) to choose how to treat tags:
error : throw a `parse_error` exception in case of a tag
error : report a parse error in case of a tag (the `from_cbor` overloads throw a `parse_error` exception by default)
ignore : ignore tags
+10 -3
View File
@@ -8,7 +8,8 @@ static bool sax_parse(InputType&& i,
input_format_t format = input_format_t::json,
const bool strict = true,
const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
const bool ignore_trailing_commas = false,
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error);
// (2)
template<class IteratorType, class SAX, class SentinelType = IteratorType>
@@ -17,13 +18,14 @@ static bool sax_parse(IteratorType first, SentinelType last,
input_format_t format = input_format_t::json,
const bool strict = true,
const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
const bool ignore_trailing_commas = false,
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error);
```
Read from input and generate SAX events
1. Read from a compatible input.
2. Read from a pair of character iterators, or an iterator and a sentinel of a different type (C++20 ranges support)
2. Read from a pair of character iterators, or an iterator and a sentinel of a different type (C++20 ranges support).
The value_type of the iterator must be an integral type with a size of 1, 2, or 4 bytes, which will be interpreted
respectively as UTF-8, UTF-16, and UTF-32. If `SentinelType` differs from `IteratorType`, it must be comparable to
@@ -82,6 +84,10 @@ The SAX event lister must follow the interface of [`json_sax`](../json_sax/index
: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
(`#!cpp false`); (optional, `#!cpp false` by default)
`tag_handler` (in)
: how to handle CBOR tags; see [`cbor_tag_handler_t`](cbor_tag_handler_t.md). Ignored for formats other than CBOR
(optional, `cbor_tag_handler_t::error` by default).
`first` (in)
: iterator to the start of a character range
@@ -137,6 +143,7 @@ A UTF-8 byte order mark is silently ignored.
- Added in version 3.2.0.
- Ignoring comments via `ignore_comments` added in version 3.9.0.
- Added `ignore_trailing_commas` in version 3.13.0.
- Added `tag_handler` in version 3.13.0.
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
- `JSON_PRECISE_STREAM_POSITION` added in version 3.13.0 to optionally leave a `#!cpp std::istream` positioned right
+6 -4
View File
@@ -5,7 +5,8 @@
<span class=w> </span><span class=n>input_format_t</span><span class=w> </span><span class=n>format</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>input_format_t</span><span class=o>::</span><span class=n>json</span><span class=p>,</span>
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=n>strict</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=nb>true</span><span class=p>,</span>
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=n>ignore_comments</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=nb>false</span><span class=p>,</span>
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=n>ignore_trailing_commas</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=nb>false</span><span class=p>);</span>
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=n>ignore_trailing_commas</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=nb>false</span><span class=p>,</span>
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>cbor_tag_handler_t</span><span class=w> </span><span class=n>tag_handler</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>cbor_tag_handler_t</span><span class=o>::</span><span class=n>error</span><span class=p>);</span>
<span class=c1>// (2)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>class</span><span class=w> </span><span class=nc>IteratorType</span><span class=p>,</span><span class=w> </span><span class=k>class</span><span class=w> </span><span class=nc>SAX</span><span class=p>,</span><span class=w> </span><span class=k>class</span><span class=w> </span><span class=nc>SentinelType</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>IteratorType</span><span class=o>&gt;</span>
@@ -14,8 +15,9 @@
<span class=w> </span><span class=n>input_format_t</span><span class=w> </span><span class=n>format</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>input_format_t</span><span class=o>::</span><span class=n>json</span><span class=p>,</span>
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=n>strict</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=nb>true</span><span class=p>,</span>
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=n>ignore_comments</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=nb>false</span><span class=p>,</span>
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=n>ignore_trailing_commas</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=nb>false</span><span class=p>);</span>
</code></pre></div> <p>Read from input and generate <abbr title="Simple API for XML">SAX</abbr> events</p> <ol> <li>Read from a compatible input.</li> <li> <p>Read from a pair of character iterators, or an iterator and a sentinel of a different type (C++20 ranges support)</p> <p>The value_type of the iterator must be an integral type with a size of 1, 2, or 4 bytes, which will be interpreted respectively as <abbr title="Unicode Transformation Format">UTF</abbr>-8, <abbr title="Unicode Transformation Format">UTF</abbr>-16, and <abbr title="Unicode Transformation Format">UTF</abbr>-32. If <code>SentinelType</code> differs from <code>IteratorType</code>, it must be comparable to the iterator type with <code>operator!=</code>.</p> </li> </ol> <p>The <abbr title="Simple API for XML">SAX</abbr> event lister must follow the interface of <a href=../../json_sax/ ><code>json_sax</code></a>.</p> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>InputType</code></dt> <dd> <p>A compatible input, for instance:</p> <ul> <li>an <code>std::istream</code> object</li> <li>a <code>FILE</code> pointer</li> <li>a C-style array of characters</li> <li>a pointer to a null-terminated string of single byte characters</li> <li>a container <code>obj</code> for which <code>begin(obj)</code> and <code>end(obj)</code> produce a valid pair of iterators (as found via <abbr title="Argument-dependent lookup">ADL</abbr> or member functions, with semantics compatible to <code>std::begin</code> and <code>std::end</code>)</li> </ul> </dd> <dt><code>IteratorType</code></dt> <dd>a compatible iterator type for overload (2); a pair of character iterators whose <code>value_type</code> is an integral type with a size of 1, 2, or 4 bytes (interpreted respectively as <abbr title="Unicode Transformation Format">UTF</abbr>-8, <abbr title="Unicode Transformation Format">UTF</abbr>-16, and <abbr title="Unicode Transformation Format">UTF</abbr>-32)</dd> <dt><code>SentinelType</code></dt> <dd> <p>defaults to <code>IteratorType</code>; may be a different type comparable to <code>IteratorType</code> via <code>operator!=</code>, for overload (2), for instance.</p> <ul> <li>a custom sentinel type for C++20 ranges</li> <li><code>std::default_sentinel_t</code>, when <code>IteratorType</code> is <code>std::counted_iterator</code></li> </ul> </dd> <dt><code>SAX</code></dt> <dd>a class fulfilling the <abbr title="Simple API for XML">SAX</abbr> event listener interface; see <a href=../../json_sax/ ><code>json_sax</code></a></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>i</code> (in)</dt> <dd>Input to parse from</dd> <dt><code>sax</code> (in)</dt> <dd><abbr title="Simple API for XML">SAX</abbr> event listener (must not be null)</dd> <dt><code>format</code> (in)</dt> <dd>the format to parse (<abbr title="JavaScript Object Notation">JSON</abbr>, <abbr title="Binary JData">BJData</abbr>, <abbr title="Binary Object Notation 8">BON8</abbr>, <abbr title="Binary JSON">BSON</abbr>, <abbr title="Concise Binary Object Representation">CBOR</abbr>, MessagePack, or <abbr title="Universal Binary JSON">UBJSON</abbr>) (optional, <code>input_format_t::json</code> by default), see <a href=../input_format_t/ ><code>input_format_t</code></a> for more information</dd> <dt><code>strict</code> (in)</dt> <dd>whether the input has to be consumed completely (optional, <code class=highlight><span class=nb>true</span></code> by default); when <code class=highlight><span class=nb>false</span></code> and the input is a <code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>istream</span></code>, the character that terminates a number is consumed unless <a href=../../macros/json_precise_stream_position/ ><code>JSON_PRECISE_STREAM_POSITION</code></a> is defined to <code>1</code>; see <a href=../../operator_gtgt/#notes><code>operator&gt;&gt;</code></a></dd> <dt><code>ignore_comments</code> (in)</dt> <dd>whether comments should be ignored and treated like whitespace (<code class=highlight><span class=nb>true</span></code>) or yield a parse error (<code class=highlight><span class=nb>false</span></code>); (optional, <code class=highlight><span class=nb>false</span></code> by default)</dd> <dt><code>ignore_trailing_commas</code> (in)</dt> <dd>whether trailing commas in arrays or objects should be ignored and treated like whitespace (<code class=highlight><span class=nb>true</span></code>) or yield a parse error (<code class=highlight><span class=nb>false</span></code>); (optional, <code class=highlight><span class=nb>false</span></code> by default)</dd> <dt><code>first</code> (in)</dt> <dd>iterator to the start of a character range</dd> <dt><code>last</code> (in)</dt> <dd>iterator to the end of a character range, or a sentinel value that compares equal to the end iterator with <code>operator!=</code><Line truncated
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=n>ignore_trailing_commas</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=nb>false</span><span class=p>,</span>
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>cbor_tag_handler_t</span><span class=w> </span><span class=n>tag_handler</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>cbor_tag_handler_t</span><span class=o>::</span><span class=n>error</span><span class=p>);</span>
</code></pre></div> <p>Read from input and generate <abbr title="Simple API for XML">SAX</abbr> events</p> <ol> <li>Read from a compatible input.</li> <li> <p>Read from a pair of character iterators, or an iterator and a sentinel of a different type (C++20 ranges support).</p> <p>The value_type of the iterator must be an integral type with a size of 1, 2, or 4 bytes, which will be interpreted respectively as <abbr title="Unicode Transformation Format">UTF</abbr>-8, <abbr title="Unicode Transformation Format">UTF</abbr>-16, and <abbr title="Unicode Transformation Format">UTF</abbr>-32. If <code>SentinelType</code> differs from <code>IteratorType</code>, it must be comparable to the iterator type with <code>operator!=</code>.</p> </li> </ol> <p>The <abbr title="Simple API for XML">SAX</abbr> event lister must follow the interface of <a href=../../json_sax/ ><code>json_sax</code></a>.</p> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>InputType</code></dt> <dd> <p>A compatible input, for instance:</p> <ul> <li>an <code>std::istream</code> object</li> <li>a <code>FILE</code> pointer</li> <li>a C-style array of characters</li> <li>a pointer to a null-terminated string of single byte characters</li> <li>a container <code>obj</code> for which <code>begin(obj)</code> and <code>end(obj)</code> produce a valid pair of iterators (as found via <abbr title="Argument-dependent lookup">ADL</abbr> or member functions, with semantics compatible to <code>std::begin</code> and <code>std::end</code>)</li> </ul> </dd> <dt><code>IteratorType</code></dt> <dd>a compatible iterator type for overload (2); a pair of character iterators whose <code>value_type</code> is an integral type with a size of 1, 2, or 4 bytes (interpreted respectively as <abbr title="Unicode Transformation Format">UTF</abbr>-8, <abbr title="Unicode Transformation Format">UTF</abbr>-16, and <abbr title="Unicode Transformation Format">UTF</abbr>-32)</dd> <dt><code>SentinelType</code></dt> <dd> <p>defaults to <code>IteratorType</code>; may be a different type comparable to <code>IteratorType</code> via <code>operator!=</code>, for overload (2), for instance.</p> <ul> <li>a custom sentinel type for C++20 ranges</li> <li><code>std::default_sentinel_t</code>, when <code>IteratorType</code> is <code>std::counted_iterator</code></li> </ul> </dd> <dt><code>SAX</code></dt> <dd>a class fulfilling the <abbr title="Simple API for XML">SAX</abbr> event listener interface; see <a href=../../json_sax/ ><code>json_sax</code></a></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>i</code> (in)</dt> <dd>Input to parse from</dd> <dt><code>sax</code> (in)</dt> <dd><abbr title="Simple API for XML">SAX</abbr> event listener (must not be null)</dd> <dt><code>format</code> (in)</dt> <dd>the format to parse (<abbr title="JavaScript Object Notation">JSON</abbr>, <abbr title="Binary JData">BJData</abbr>, <abbr title="Binary Object Notation 8">BON8</abbr>, <abbr title="Binary JSON">BSON</abbr>, <abbr title="Concise Binary Object Representation">CBOR</abbr>, MessagePack, or <abbr title="Universal Binary JSON">UBJSON</abbr>) (optional, <code>input_format_t::json</code> by default), see <a href=../input_format_t/ ><code>input_format_t</code></a> for more information</dd> <dt><code>strict</code> (in)</dt> <dd>whether the input has to be consumed completely (optional, <code class=highlight><span class=nb>true</span></code> by default); when <code class=highlight><span class=nb>false</span></code> and the input is a <code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>istream</span></code>, the character that terminates a number is consumed unless <a href=../../macros/json_precise_stream_position/ ><code>JSON_PRECISE_STREAM_POSITION</code></a> is defined to <code>1</code>; see <a href=../../operator_gtgt/#notes><code>operator&gt;&gt;</code></a></dd> <dt><code>ignore_comments</code> (in)</dt> <dd>whether comments should be ignored and treated like whitespace (<code class=highlight><span class=nb>true</span></code>) or yield a parse error (<code class=highlight><span class=nb>false</span></code>); (optional, <code class=highlight><span class=nb>false</span></code> by default)</dd> <dt><code>ignore_trailing_commas</code> (in)</dt> <dd>whether trailing commas in arrays or objects should be ignored and treated like whitespace (<code class=highlight><span class=nb>true</span></code>) or yield a parse error (<code class=highlight><span class=nb>false</span></code>); (optional, <code class=highlight><span class=nb>false</span></code> by default)</dd> <dt><code>tag_handler</code> (in)</dt> <dd>how to handle <abbr title="Concise Binary Object Representation">CBOR</abbr> tags; see <a href=../cbor_tag_handler_t/ ><code>cbor_tag_handler_t</code></a>. Ignored for formats other than <abbr title="Concise Line truncated
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iomanip&gt;</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;sstream&gt;</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span>
@@ -183,4 +185,4 @@
<span class=w> </span><span class=err>ex=</span><span class=p>[</span><span class=err>jso</span><span class=kc>n</span><span class=err>.excep</span><span class=kc>t</span><span class=err>io</span><span class=kc>n</span><span class=err>.parse_error.</span><span class=mi>101</span><span class=p>]</span><span class=w> </span><span class=err>parse</span><span class=w> </span><span class=err>error</span><span class=w> </span><span class=err>a</span><span class=kc>t</span><span class=w> </span><span class=err>li</span><span class=kc>ne</span><span class=w> </span><span class=mi>17</span><span class=p>,</span><span class=w> </span><span class=err>colum</span><span class=kc>n</span><span class=w> </span><span class=mi>6</span><span class=p>:</span><span class=w> </span><span class=err>sy</span><span class=kc>nta</span><span class=err>x</span><span class=w> </span><span class=err>error</span><span class=w> </span><span class=err>while</span><span class=w> </span><span class=err>parsi</span><span class=kc>n</span><span class=err>g</span><span class=w> </span><span class=err>value</span><span class=w> </span><span class=mi>-</span><span class=w> </span><span class=err>u</span><span class=kc>ne</span><span class=err>xpec</span><span class=kc>te</span><span class=err>d</span><span class=w> </span><span class=err>'</span><span class=p>]</span><span class=err>';</span><span class=w> </span><span class=err>expec</span><span class=kc>te</span><span class=err>d</span><span class=w> </span><span class=err>e</span><span class=kc>n</span><span class=err>d</span><span class=w> </span><span class=err>o</span><span class=kc>f</span><span class=w> </span><span class=err>i</span><span class=kc>n</span><span class=err>pu</span><span class=kc>t</span><span class=err>)</span>
<span class=err>resul</span><span class=kc>t</span><span class=p>:</span><span class=w> </span><span class=kc>false</span>
</code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../parse/ >parse</a> - deserialize from a compatible input</li> <li><a href=../accept/ >accept</a> - check if the input is valid <abbr title="JavaScript Object Notation">JSON</abbr></li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ul> <li>Added in version 3.2.0.</li> <li>Ignoring comments via <code>ignore_comments</code> added in version 3.9.0.</li> <li>Added <code>ignore_trailing_commas</code> in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>.</li> <li>Extended container support (1) to include types with lvalue-only <abbr title="Argument-dependent lookup">ADL</abbr> <code>begin</code>/<code>end</code> (matching <code>std::begin</code>/<code>std::end</code> semantics) in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>.</li> <li>Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>.</li> <li><code>JSON_PRECISE_STREAM_POSITION</code> added in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span> to optionally leave a <code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>istream</span></code> positioned right after the parsed value when <code>strict</code> is <code class=highlight><span class=nb>false</span></code>.</li> </ul> <div class="admonition warning"> <p class=admonition-title>Deprecation</p> <p>Overload (2) replaces calls to <code>sax_parse</code> with a pair of iterators as their first parameter which has been deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like <code class=highlight><span class=n>sax_parse</span><span class=p>({</span><span class=n>ptr</span><span class=p>,</span><span class=w> </span><span class=n>ptr</span><span class=o>+</span><span class=n>len</span><span class=p>});</span></code> with <code class=highlight><span class=n>sax_parse</span><span class=p>(</span><span class=n>ptr</span><span class=p>,</span><span class=w> </span><span class=n>ptr</span><span class=o>+</span><span class=n>len</span><span class=p>);</span></code>.</p> <p>See the <a href=../../../integration/migration_guide/#parsing>migration guide</a> for how to update existing code.</p> </div> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 09:32:15 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.Line truncated
</code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../parse/ >parse</a> - deserialize from a compatible input</li> <li><a href=../accept/ >accept</a> - check if the input is valid <abbr title="JavaScript Object Notation">JSON</abbr></li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ul> <li>Added in version 3.2.0.</li> <li>Ignoring comments via <code>ignore_comments</code> added in version 3.9.0.</li> <li>Added <code>ignore_trailing_commas</code> in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>.</li> <li>Added <code>tag_handler</code> in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>.</li> <li>Extended container support (1) to include types with lvalue-only <abbr title="Argument-dependent lookup">ADL</abbr> <code>begin</code>/<code>end</code> (matching <code>std::begin</code>/<code>std::end</code> semantics) in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>.</li> <li>Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>.</li> <li><code>JSON_PRECISE_STREAM_POSITION</code> added in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span> to optionally leave a <code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>istream</span></code> positioned right after the parsed value when <code>strict</code> is <code class=highlight><span class=nb>false</span></code>.</li> </ul> <div class="admonition warning"> <p class=admonition-title>Deprecation</p> <p>Overload (2) replaces calls to <code>sax_parse</code> with a pair of iterators as their first parameter which has been deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like <code class=highlight><span class=n>sax_parse</span><span class=p>({</span><span class=n>ptr</span><span class=p>,</span><span class=w> </span><span class=n>ptr</span><span class=o>+</span><span class=n>len</span><span class=p>});</span></code> with <code class=highlight><span class=n>sax_parse</span><span class=p>(</span><span class=n>ptr</span><span class=p>,</span><span class=w> </span><span class=n>ptr</span><span class=o>+</span><span class=n>len</span><span class=p>);</span></code>.</p> <p>See the <a href=../../../integration/migration_guide/#parsing>migration guide</a> for how to update existing code.</p> </div> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 7, 2026 05:38:24 UTC">October 7, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0Line truncated
+8 -3
View File
@@ -8,7 +8,8 @@ static bool sax_parse(InputType&& i,
input_format_t format = input_format_t::json,
const bool strict = true,
const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
const bool ignore_trailing_commas = false,
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error);
// (2)
template<class IteratorType, class SAX, class SentinelType = IteratorType>
@@ -17,14 +18,15 @@ static bool sax_parse(IteratorType first, SentinelType last,
input_format_t format = input_format_t::json,
const bool strict = true,
const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
const bool ignore_trailing_commas = false,
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error);
```
Read from input and generate SAX events
1. Read from a compatible input.
1. Read from a pair of character iterators, or an iterator and a sentinel of a different type (C++20 ranges support)
1. Read from a pair of character iterators, or an iterator and a sentinel of a different type (C++20 ranges support).
The value_type of the iterator must be an integral type with a size of 1, 2, or 4 bytes, which will be interpreted respectively as UTF-8, UTF-16, and UTF-32. If `SentinelType` differs from `IteratorType`, it must be comparable to the iterator type with `operator!=`.
@@ -68,6 +70,8 @@ The SAX event lister must follow the interface of [`json_sax`](https://json.nloh
`ignore_trailing_commas` (in) : whether trailing commas in arrays or objects should be ignored and treated like whitespace (`true`) or yield a parse error (`false`); (optional, `false` by default)
`tag_handler` (in) : how to handle CBOR tags; see [`cbor_tag_handler_t`](https://json.nlohmann.me/api/basic_json/cbor_tag_handler_t/index.md). Ignored for formats other than CBOR (optional, `cbor_tag_handler_t::error` by default).
`first` (in) : iterator to the start of a character range
`last` (in) : iterator to the end of a character range, or a sentinel value that compares equal to the end iterator with `operator!=`
@@ -284,6 +288,7 @@ result: false
- Added in version 3.2.0.
- Ignoring comments via `ignore_comments` added in version 3.9.0.
- Added `ignore_trailing_commas` in version 3.13.0 unreleased.
- Added `tag_handler` in version 3.13.0 unreleased.
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0 unreleased.
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0 unreleased.
- `JSON_PRECISE_STREAM_POSITION` added in version 3.13.0 unreleased to optionally leave a `std::istream` positioned right after the parsed value when `strict` is `false`.