This commit is contained in:
nlohmann committed 2026-10-26 21:24:35 +00:00
1 parent 41c601a7d1
commit d2e264bd84
1400 files changed
+11859 -5440

No files matched your search

+4 -4
View File
@@ -1,4 +1,4 @@
<!doctype html><html lang=en class=no-js> <head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=author content="Niels Lohmann"><link href="https://json.nlohmann.me/api/operator_gtgt/" rel="canonical"><link href=../operator_ltlt/ rel=prev><link href=../operator_literal_json/ rel=next><link rel=icon href=../../assets/images/favicon.png><meta name=generator content="mkdocs-1.6.1, mkdocs-material-9.7.7"><title>operator>>(basic_json) - JSON for Modern C++</title><link rel=stylesheet href=../../assets/stylesheets/main.ec1eaa64.min.css><link rel=stylesheet href=../../assets/stylesheets/palette.ab4e12ef.min.css><link rel="stylesheet" href="../../assets/external/fonts.googleapis.com/css.61a430c9.css"><style>:root{--md-text-font:"Roboto";--md-code-font:"JetBrains Mono"}</style><link rel=stylesheet href=../../css/custom.css><script>__md_scope=new URL("../..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script></head> <body dir=ltr data-md-color-scheme=default data-md-color-primary=indigo data-md-color-accent=indigo> <input class=md-toggle data-md-toggle=drawer type=checkbox id=__drawer autocomplete=off> <input class=md-toggle data-md-toggle=search type=checkbox id=__search autocomplete=off> <label class=md-overlay for=__drawer></label> <div data-md-component=skip> <a href=#nlohmannoperatorbasic_json class=md-skip> Skip to content </a> </div> <div data-md-component=announce> </div> <header class=md-header data-md-component=header> <nav class="md-header__inner md-grid" aria-label=Header> <a href=../.. title="JSON for Modern C++" class="md-header__button md-logo" aria-label="JSON for Modern C++" data-md-component=logo> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg> </a> <label class="md-header__button md-icon" for=__drawer> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg> </label> <div class=md-header__title data-md-component=header-title> <div class=md-header__ellipsis> <div class=md-header__topic> <span class=md-ellipsis> JSON for Modern C++ </span> </div> <div class=md-header__topic data-md-component=header-topic> <span class=md-ellipsis> operator>>(basic_json) </span> </div> </div> </div> <form class=md-header__option data-md-component=palette> <input class=md-option data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme=default data-md-color-primary=indigo data-md-color-accent=indigo aria-label="Switch to dark mode" type=radio name=__palette id=__palette_0> <label class="md-header__button md-icon" title="Switch to dark mode" for=__palette_1 hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"/></svg> </label> <input class=md-option data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme=slate data-md-color-primary=indigo data-md-color-accent=indigo aria-label="Switch to light mode" type=radio name=__palette id=__palette_1> <label class="md-header__button md-icon" title="Switch to light mode" for=__palette_0 hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12s-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"/></svg> </label> </form> <script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script> <label class="md-header__button md-icon" for=__search> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5Line truncated
<!doctype html><html lang=en class=no-js> <head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=author content="Niels Lohmann"><link href="https://json.nlohmann.me/api/operator_gtgt/" rel="canonical"><link href=../operator_ltlt/ rel=prev><link href=../operator_literal_json/ rel=next><link rel=icon href=../../assets/images/favicon.png><meta name=generator content="mkdocs-1.6.1, mkdocs-material-9.7.7"><title>operator>>(basic_json) - JSON for Modern C++</title><link rel=stylesheet href=../../assets/stylesheets/main.ec1eaa64.min.css><link rel=stylesheet href=../../assets/stylesheets/palette.ab4e12ef.min.css><link rel="stylesheet" href="../../assets/external/fonts.googleapis.com/css.61a430c9.css"><style>:root{--md-text-font:"Roboto";--md-code-font:"JetBrains Mono"}</style><link rel=stylesheet href=../../css/custom.css><script>__md_scope=new URL("../..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script></head> <body dir=ltr data-md-color-scheme=default data-md-color-primary=indigo data-md-color-accent=indigo> <input class=md-toggle data-md-toggle=drawer type=checkbox id=__drawer autocomplete=off> <input class=md-toggle data-md-toggle=search type=checkbox id=__search autocomplete=off> <label class=md-overlay for=__drawer></label> <div data-md-component=skip> <a href=#nlohmannoperatorbasic_json class=md-skip> Skip to content </a> </div> <div data-md-component=announce> </div> <header class=md-header data-md-component=header> <nav class="md-header__inner md-grid" aria-label=Header> <a href=../.. title="JSON for Modern C++" class="md-header__button md-logo" aria-label="JSON for Modern C++" data-md-component=logo> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg> </a> <label class="md-header__button md-icon" for=__drawer> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg> </label> <div class=md-header__title data-md-component=header-title> <div class=md-header__ellipsis> <div class=md-header__topic> <span class=md-ellipsis> JSON for Modern C++ </span> </div> <div class=md-header__topic data-md-component=header-topic> <span class=md-ellipsis> operator>>(basic_json) </span> </div> </div> </div> <form class=md-header__option data-md-component=palette> <input class=md-option data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme=default data-md-color-primary=indigo data-md-color-accent=indigo aria-label="Switch to dark mode" type=radio name=__palette id=__palette_0> <label class="md-header__button md-icon" title="Switch to dark mode" for=__palette_1 hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"/></svg> </label> <input class=md-option data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme=slate data-md-color-primary=indigo data-md-color-accent=indigo aria-label="Switch to light mode" type=radio name=__palette id=__palette_1> <label class="md-header__button md-icon" title="Switch to light mode" for=__palette_0 hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12s-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"/></svg> </label> </form> <script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script> <label class="md-header__button md-icon" for=__search> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5Line truncated
</code></pre></div> <p>Deserializes an input stream to a <abbr title="JavaScript Object Notation">JSON</abbr> value.</p> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>i</code> (in, out)</dt> <dd>input stream to read a serialized <abbr title="JavaScript Object Notation">JSON</abbr> value from</dd> <dt><code>j</code> (in, out)</dt> <dd><abbr title="JavaScript Object Notation">JSON</abbr> value to write the deserialized input to</dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>the stream <code>i</code></p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <p>Strong guarantee: if an exception is thrown, there are no changes in <code>j</code>.</p> <h2 id=exceptions>Exceptions<a class=headerlink href=#exceptions title="Permanent link">&para;</a></h2> <ul> <li>Throws <a href=../../home/exceptions/#jsonexceptionparse_error101><code>parse_error.101</code></a> in case of an unexpected token, or if <code>i</code> has no stream buffer (<code class=highlight><span class=n>i</span><span class=p>.</span><span class=n>rdbuf</span><span class=p>()</span><span class=w> </span><span class=o>==</span><span class=w> </span><span class=nb>nullptr</span></code>, for instance <code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>istream</span><span class=p>(</span><span class=nb>nullptr</span><span class=p>)</span></code>).</li> <li>If reading from <code>i</code> reaches the end of the input and <code>eofbit</code> is part of <code>i</code>'s <a href="https://en.cppreference.com/w/cpp/io/basic_ios/exceptions"><code>exceptions()</code></a> mask, the <code>std::ios_base::failure</code> thrown by <code>i</code> itself propagates instead of a <code>parse_error</code>, the same as it would for the standard library's own extraction operators.</li> </ul> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear in the length of the input. The parser is a predictive LL(1) parser.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <p>A <abbr title="Unicode Transformation Format">UTF</abbr>-8 byte order mark is silently ignored.</p> <p>Invalid Unicode escapes and unpaired surrogates in the input are reported as <a href=../../home/exceptions/#jsonexceptionparse_error101><code>parse_error.101</code></a> with a detailed message.</p> <p><code>operator&gt;&gt;</code> parses exactly one <abbr title="JavaScript Object Notation">JSON</abbr> value, so it can be called repeatedly to read a sequence of concatenated <abbr title="JavaScript Object Notation">JSON</abbr> values from the same stream:</p> <div class=highlight><pre><span></span><code><span class=n>json</span><span class=w> </span><span class=n>j1</span><span class=p>,</span><span class=w> </span><span class=n>j2</span><span class=p>;</span>
<span class=n>input</span><span class=w> </span><span class=o>&gt;&gt;</span><span class=w> </span><span class=n>j1</span><span class=p>;</span><span class=w> </span><span class=c1>// parses the first value</span>
<span class=n>input</span><span class=w> </span><span class=o>&gt;&gt;</span><span class=w> </span><span class=n>j2</span><span class=p>;</span><span class=w> </span><span class=c1>// parses the next value</span>
@@ -10,12 +10,12 @@
<span class=n>json</span><span class=w> </span><span class=n>j1</span><span class=p>,</span><span class=w> </span><span class=n>j2</span><span class=p>;</span>
<span class=n>input</span><span class=w> </span><span class=o>&gt;&gt;</span><span class=w> </span><span class=n>j1</span><span class=p>;</span><span class=w> </span><span class=c1>// j1 == 1</span>
<span class=n>input</span><span class=w> </span><span class=o>&gt;&gt;</span><span class=w> </span><span class=n>j2</span><span class=p>;</span><span class=w> </span><span class=c1>// j2 == true</span>
</code></pre></div> <p>Only numbers are affected. Values ending in a self-delimiting character do not read past themselves, so <code>truefalse</code>, <code>[1][2]</code>, <code>{"a":1}{"b":2}</code>, and <code>"a""b"</code> can be read back to back without a separator.</p> <p>Define <a href=../macros/json_precise_stream_position/ ><code>JSON_PRECISE_STREAM_POSITION</code></a> to <code>1</code> to leave the terminating character in the stream instead, so that the stream is positioned right after the value for every value type and no separator is needed. This is tracked in <a href="https://github.com/nlohmann/json/issues/5340">#5340</a>.</p> </div> <p>Note that reading concatenated values does <strong>not</strong> work for <a href=../../features/parsing/json_lines/ ><abbr title="JavaScript Object Notation">JSON</abbr> Lines</a> (newline-delimited <abbr title="JavaScript Object Notation">JSON</abbr>) input -- see that page for why and for the recommended alternative.</p> <p>By default, a <code>'\0'</code> (NUL) byte encountered while reading a value is treated as end of input, rather than as an ordinary (and, outside of a string, invalid) byte; see the <a href=../../home/faq/#nul-bytes-in-the-input><abbr title="Frequently Asked Questions">FAQ</abbr> entry</a> for details and the <a href=../macros/json_strict_nul_handling/ ><code>JSON_STRICT_NUL_HANDLING</code></a> macro to opt into rejecting it instead. Because <code>operator&gt;&gt;</code> only parses a single value and does not require the rest of the stream to be consumed, a NUL byte <em>after</em> a complete value has no effect on <code>operator&gt;&gt;</code> either way; it only matters while a value is still being read.</p> <div class="admonition warning"> <p class=admonition-title>Deprecation</p> <p>This function replaces function <code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>istream</span><span class=o>&amp;</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;&lt;</span><span class=p>(</span><span class=n>basic_json</span><span class=o>&amp;</span><span class=w> </span><span class=n>j</span><span class=p>,</span><span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>istream</span><span class=o>&amp;</span><span class=w> </span><span class=n>i</span><span class=p>)</span></code> which has been deprecated in version 3.0.0. It will be removed in version 4.0.0. Please replace calls like <code class=highlight><span class=n>j</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=n>i</span><span class=p>;</span></code> with <code class=highlight><span class=n>i</span><span class=w> </span><span class=o>&gt;&gt;</span><span class=w> </span><span class=n>j</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> <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 a <abbr title="JavaScript Object Notation">JSON</abbr> value is constructed by reading a serialization from a stream.</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>Only numbers are affected. Values ending in a self-delimiting character do not read past themselves, so <code>truefalse</code>, <code>[1][2]</code>, <code>{"a":1}{"b":2}</code>, and <code>"a""b"</code> can be read back to back without a separator.</p> <p>Define <a href=../macros/json_precise_stream_position/ ><code>JSON_PRECISE_STREAM_POSITION</code></a> to <code>1</code> to leave the terminating character in the stream instead, so that the stream is positioned right after the value for every value type and no separator is needed. This is tracked in <a href="https://github.com/nlohmann/json/issues/5340">#5340</a>.</p> </div> <p>Note that reading concatenated values does <strong>not</strong> work for <a href=../../features/parsing/json_lines/ ><abbr title="JavaScript Object Notation">JSON</abbr> Lines</a> (newline-delimited <abbr title="JavaScript Object Notation">JSON</abbr>) input -- see that page for why and for the recommended alternative.</p> <p>By default, a <code>'\0'</code> (<abbr title="Null character (U+0000, byte value 0)">NUL</abbr>) byte encountered while reading a value is treated as end of input, rather than as an ordinary (and, outside of a string, invalid) byte; see the <a href=../../home/faq/#nul-bytes-in-the-input><abbr title="Frequently Asked Questions">FAQ</abbr> entry</a> for details and the <a href=../macros/json_strict_nul_handling/ ><code>JSON_STRICT_NUL_HANDLING</code></a> macro to opt into rejecting it instead. Because <code>operator&gt;&gt;</code> only parses a single value and does not require the rest of the stream to be consumed, a <abbr title="Null character (U+0000, byte value 0)">NUL</abbr> byte <em>after</em> a complete value has no effect on <code>operator&gt;&gt;</code> either way; it only matters while a value is still being read.</p> <div class="admonition warning"> <p class=admonition-title>Deprecation</p> <p>This function replaces function <code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>istream</span><span class=o>&amp;</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;&lt;</span><span class=p>(</span><span class=n>basic_json</span><span class=o>&amp;</span><span class=w> </span><span class=n>j</span><span class=p>,</span><span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>istream</span><span class=o>&amp;</span><span class=w> </span><span class=n>i</span><span class=p>)</span></code> which has been deprecated in version 3.0.0. It will be removed in version 4.0.0. Please replace calls like <code class=highlight><span class=n>j</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=n>i</span><span class=p>;</span></code> with <code class=highlight><span class=n>i</span><span class=w> </span><span class=o>&gt;&gt;</span><span class=w> </span><span class=n>j</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> <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 a <abbr title="JavaScript Object Notation">JSON</abbr> value is constructed by reading a serialization from a stream.</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;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>
<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>
<span class=k>using</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span>
<span class=kt>int</span><span class=w> </span><span class=nf>main</span><span class=p>()</span>
<span class=p>{</span>
@@ -49,4 +49,4 @@
<span class=w> </span><span class=nt>"number"</span><span class=p>:</span><span class=w> </span><span class=mi>23</span><span class=p>,</span>
<span class=w> </span><span class=nt>"string"</span><span class=p>:</span><span class=w> </span><span class=s2>"Hello, world!"</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=../basic_json/accept/ >accept</a> - check if the input is valid <abbr title="JavaScript Object Notation">JSON</abbr></li> <li><a href=../basic_json/parse/ >parse</a> - deserialize from a compatible input</li> <li><a href=../macros/json_strict_nul_handling/ ><code>JSON_STRICT_NUL_HANDLING</code></a> - opt in to rejecting a NUL byte in the input instead of treating it as end of input</li> <li><a href=../macros/json_precise_stream_position/ ><code>JSON_PRECISE_STREAM_POSITION</code></a> - opt in to leaving the stream positioned right after a number</li> <li><a href=../macros/json_disable_stream_bulk_scan/ ><code>JSON_DISABLE_STREAM_BULK_SCAN</code></a> - read the stream one character at a time</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 1.0.0.</li> <li><code>JSON_STRICT_NUL_HANDLING</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 reject a NUL byte in the input instead of treating it as end of input; planned to become the default in version 4.0.0.</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 the character that terminates a number in the stream; planned to become the default in version 4.0.0.</li> <li>Fixed a null pointer dereference for an <code>std::istream</code> without a stream buffer (now throws <code>parse_error.101</code>), and a crash (<code>std::terminate</code>) when <code>i</code> has <code>eofbit</code> in its exception mask, 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>Changed to the strong exception safety guarantee 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>: <code>j</code> is no longer left with a partially parsed value if parsing throws.</li> <li>Scans the characters in the stream buffer of <code>i</code> in bulk 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>; the position of <code>i</code> after the call is unchanged (<a href=../macros/json_disable_stream_bulk_scan/ ><code>JSON_DISABLE_STREAM_BULK_SCAN</code></a> restores reading one character at a time).</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 19, 2026 20:00:58 UTC">October 19, 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 2Line 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=../basic_json/accept/ >accept</a> - check if the input is valid <abbr title="JavaScript Object Notation">JSON</abbr></li> <li><a href=../basic_json/parse/ >parse</a> - deserialize from a compatible input</li> <li><a href=../macros/json_strict_nul_handling/ ><code>JSON_STRICT_NUL_HANDLING</code></a> - opt in to rejecting a <abbr title="Null character (U+0000, byte value 0)">NUL</abbr> byte in the input instead of treating it as end of input</li> <li><a href=../macros/json_precise_stream_position/ ><code>JSON_PRECISE_STREAM_POSITION</code></a> - opt in to leaving the stream positioned right after a number</li> <li><a href=../macros/json_disable_stream_bulk_scan/ ><code>JSON_DISABLE_STREAM_BULK_SCAN</code></a> - read the stream one character at a time</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 1.0.0.</li> <li><code>JSON_STRICT_NUL_HANDLING</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 reject a <abbr title="Null character (U+0000, byte value 0)">NUL</abbr> byte in the input instead of treating it as end of input; planned to become the default in version 4.0.0.</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 the character that terminates a number in the stream; planned to become the default in version 4.0.0.</li> <li>Fixed a null pointer dereference for an <code>std::istream</code> without a stream buffer (now throws <code>parse_error.101</code>), and a crash (<code>std::terminate</code>) when <code>i</code> has <code>eofbit</code> in its exception mask, 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>Changed to the strong exception safety guarantee 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>: <code>j</code> is no longer left with a partially parsed value if parsing throws.</li> <li>Scans the characters in the stream buffer of <code>i</code> in bulk 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>; the position of <code>i</code> after the call is unchanged (<a href=../macros/json_disable_stream_bulk_scan/ ><code>JSON_DISABLE_STREAM_BULK_SCAN</code></a> restores reading one character at a time).</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 19, 2026 20:00:58 UTC">October 19, 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.--><pLine truncated