This commit is contained in:
nlohmann committed 2026-10-03 05:43:12 +00:00
1 parent 2aaa1d24ef
commit a410b4f40f
741 files changed
+8115 -2252

No files matched your search

+29 -29
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/home/exceptions/" rel="canonical"><link href=../faq/ rel=prev><link href=../releases/ rel=next><link rel=icon href=../../assets/images/favicon.png><meta name=generator content="mkdocs-1.6.1, mkdocs-material-9.7.7"><title>Exceptions - 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=#exceptions 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> Exceptions </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.5 12 5 9.5 5"/></svg> </label> <div class=md-search data-md-componLine 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/home/exceptions/" rel="canonical"><link href=../faq/ rel=prev><link href=../releases/ rel=next><link rel=icon href=../../assets/images/favicon.png><meta name=generator content="mkdocs-1.6.1, mkdocs-material-9.7.7"><title>Exceptions - 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=#exceptions 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> Exceptions </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.5 12 5 9.5 5"/></svg> </label> <div class=md-search data-md-componLine truncated
direction LR
class `std::exception` {
&lt;&lt;interface&gt;&gt;
@@ -23,7 +23,7 @@
`json::exception` &lt;|-- `json::invalid_iterator`
`json::exception` &lt;|-- `json::type_error`
`json::exception` &lt;|-- `json::out_of_range`
`json::exception` &lt;|-- `json::other_error`</code></pre> <h3 id=switch-off-exceptions>Switch off exceptions<a class=headerlink href=#switch-off-exceptions title="Permanent link">&para;</a></h3> <p>Exceptions are used widely within the library. They can, however, be switched off with either using the compiler flag <code>-fno-exceptions</code> or by defining the symbol <a href=../../api/macros/json_noexception/ ><code>JSON_NOEXCEPTION</code></a>. In this case, exceptions are replaced by <code>abort()</code> calls. You can further control this behavior by defining <code>JSON_THROW_USER</code> (overriding <code class=highlight><span class=k>throw</span></code>), <code>JSON_TRY_USER</code> (overriding <code class=highlight><span class=k>try</span></code>), and <code>JSON_CATCH_USER</code> (overriding <code class=highlight><span class=k>catch</span></code>).</p> <p>Note that <a href=../../api/macros/json_throw_user/ ><code>JSON_THROW_USER</code></a> should leave the current scope (e.g., by throwing or aborting), as continuing after it may yield undefined behavior.</p> <details class=example> <summary>Example</summary> <p>The code below switches off exceptions and creates a log entry with a detailed error message in case of errors.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span>
`json::exception` &lt;|-- `json::other_error`</code></pre> <h3 id=switch-off-exceptions>Switch off exceptions<a class=headerlink href=#switch-off-exceptions title="Permanent link">&para;</a></h3> <p>Exceptions are used widely within the library. They can, however, be switched off with either using the compiler flag <code>-fno-exceptions</code> or by defining the symbol <a href=../../api/macros/json_noexception/ ><code>JSON_NOEXCEPTION</code></a>. In this case, exceptions are replaced by <code>abort()</code> calls. You can further control this behavior by defining <code>JSON_THROW_USER</code> (overriding <code class=highlight><span class=k>throw</span></code>), <code>JSON_TRY_USER</code> (overriding <code class=highlight><span class=k>try</span></code>), and <code>JSON_CATCH_USER</code> (overriding <code class=highlight><span class=k>catch</span></code>).</p> <p>Note that <a href=../../api/macros/json_throw_user/ ><code>JSON_THROW_USER</code></a> should leave the current scope (e.g., by throwing or aborting), as continuing after it may yield undefined behavior.</p> <details class=example> <summary>Example: switch off exceptions and log errors before aborting</summary> <p>The code below switches off exceptions and creates a log entry with a detailed error message in case of errors.</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>#define JSON_TRY_USER if(true)</span>
<span class=cp>#define JSON_CATCH_USER(exception) if(false)</span>
@@ -34,7 +34,7 @@
<span class=cp> std::abort();}</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span>
</code></pre></div> </details> <p>Note the explanatory <a href="https://en.cppreference.com/w/cpp/error/exception/what"><code>what()</code></a> string of exceptions is not available for <abbr title="Microsoft Visual C++">MSVC</abbr> if exceptions are disabled, see <a href="https://github.com/nlohmann/json/discussions/2824">#2824</a>.</p> <p>See <a href=../../api/macros/json_throw_user/ >documentation of <code>JSON_TRY_USER</code>, <code>JSON_CATCH_USER</code> and <code>JSON_THROW_USER</code></a> for more information.</p> <h3 id=extended-diagnostic-messages>Extended diagnostic messages<a class=headerlink href=#extended-diagnostic-messages title="Permanent link">&para;</a></h3> <p>Exceptions in the library are thrown in the local context of the <abbr title="JavaScript Object Notation">JSON</abbr> value they are detected. This makes detailed diagnostics messages, and hence debugging, difficult.</p> <details class=example> <summary>Example</summary> <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> </details> <p>Note the explanatory <a href="https://en.cppreference.com/w/cpp/error/exception/what"><code>what()</code></a> string of exceptions is not available for <abbr title="Microsoft Visual C++">MSVC</abbr> if exceptions are disabled, see <a href="https://github.com/nlohmann/json/discussions/2824">#2824</a>.</p> <p>See <a href=../../api/macros/json_throw_user/ >documentation of <code>JSON_TRY_USER</code>, <code>JSON_CATCH_USER</code> and <code>JSON_THROW_USER</code></a> for more information.</p> <h3 id=extended-diagnostic-messages>Extended diagnostic messages<a class=headerlink href=#extended-diagnostic-messages title="Permanent link">&para;</a></h3> <p>Exceptions in the library are thrown in the local context of the <abbr title="JavaScript Object Notation">JSON</abbr> value they are detected. This makes detailed diagnostics messages, and hence debugging, difficult.</p> <details class=example> <summary>Example: standard diagnostic message</summary> <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>
@@ -55,7 +55,7 @@
<span class=w> </span><span class=p>}</span>
<span class=p>}</span>
</code></pre></div> <p>Output:</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.302] type must be number, but is string
</code></pre></div> <p>This exception can be hard to debug if storing the value <code class=highlight><span class=s>"12"</span></code> and accessing it is further apart.</p> </details> <p>To create better diagnostics messages, each <abbr title="JavaScript Object Notation">JSON</abbr> value needs a pointer to its parent value such that a global context (i.e., a path from the root value to the value that led to the exception) can be created. That global context is provided as <a href=../../features/json_pointer/ ><abbr title="JavaScript Object Notation">JSON</abbr> Pointer</a>.</p> <p>As this global context comes at the price of storing one additional pointer per <abbr title="JavaScript Object Notation">JSON</abbr> value and runtime overhead to maintain the parent relation, extended diagnostics are disabled by default. They can, however, be enabled by defining the preprocessor symbol <a href=../../api/macros/json_diagnostics/ ><code>JSON_DIAGNOSTICS</code></a> to <code>1</code> before including <code>json.hpp</code>.</p> <details class=example> <summary>Example</summary> <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 exception can be hard to debug if storing the value <code class=highlight><span class=s>"12"</span></code> and accessing it is further apart.</p> </details> <p>To create better diagnostics messages, each <abbr title="JavaScript Object Notation">JSON</abbr> value needs a pointer to its parent value such that a global context (i.e., a path from the root value to the value that led to the exception) can be created. That global context is provided as <a href=../../features/json_pointer/ ><abbr title="JavaScript Object Notation">JSON</abbr> Pointer</a>.</p> <p>As this global context comes at the price of storing one additional pointer per <abbr title="JavaScript Object Notation">JSON</abbr> value and runtime overhead to maintain the parent relation, extended diagnostics are disabled by default. They can, however, be enabled by defining the preprocessor symbol <a href=../../api/macros/json_diagnostics/ ><code>JSON_DIAGNOSTICS</code></a> to <code>1</code> before including <code>json.hpp</code>.</p> <details class=example> <summary>Example: extended diagnostic message with <code>JSON_DIAGNOSTICS</code></summary> <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># define JSON_DIAGNOSTICS 1</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span>
@@ -78,7 +78,7 @@
<span class=w> </span><span class=p>}</span>
<span class=p>}</span>
</code></pre></div> <p>Output:</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.302] (/address/housenumber) type must be number, but is string
</code></pre></div> <p>Now the exception message contains a <abbr title="JavaScript Object Notation">JSON</abbr> Pointer <code>/address/housenumber</code> that indicates which value has the wrong type.</p> </details> <p>See <a href=../../api/macros/json_diagnostics/ >documentation of <code>JSON_DIAGNOSTICS</code></a> for more information.</p> <h2 id=parse-errors>Parse errors<a class=headerlink href=#parse-errors title="Permanent link">&para;</a></h2> <p>The library throws this exception when a parse error occurs. Parse errors can occur during the deserialization of <abbr title="JavaScript Object Notation">JSON</abbr> text, <abbr title="Concise Binary Object Representation">CBOR</abbr>, MessagePack, as well as when using <abbr title="JavaScript Object Notation">JSON</abbr> Patch.</p> <p>Exceptions have ids 1xx.</p> <div class="admonition info"> <p class=admonition-title>Byte index</p> <p>Member <code>byte</code> holds the byte index of the last read character in the input file.</p> <p>For an input with n bytes, 1 is the index of the first character and n+1 is the index of the terminating null byte or the end of file. This also holds true when reading a byte vector (<abbr title="Concise Binary Object Representation">CBOR</abbr> or MessagePack).</p> </div> <details class=example> <summary>Example</summary> <p>The following code shows how a <code>parse_error</code> exception can be caught.</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>Now the exception message contains a <abbr title="JavaScript Object Notation">JSON</abbr> Pointer <code>/address/housenumber</code> that indicates which value has the wrong type.</p> </details> <p>See <a href=../../api/macros/json_diagnostics/ >documentation of <code>JSON_DIAGNOSTICS</code></a> for more information.</p> <h2 id=parse-errors>Parse errors<a class=headerlink href=#parse-errors title="Permanent link">&para;</a></h2> <p>The library throws this exception when a parse error occurs. Parse errors can occur during the deserialization of <abbr title="JavaScript Object Notation">JSON</abbr> text, <abbr title="Concise Binary Object Representation">CBOR</abbr>, MessagePack, as well as when using <abbr title="JavaScript Object Notation">JSON</abbr> Patch.</p> <p>Exceptions have ids 1xx.</p> <div class="admonition info"> <p class=admonition-title>Byte index</p> <p>Member <code>byte</code> holds the byte index of the last read character in the input file.</p> <p>For an input with n bytes, 1 is the index of the first character and n+1 is the index of the terminating null byte or the end of file. This also holds true when reading a byte vector (<abbr title="Concise Binary Object Representation">CBOR</abbr> or MessagePack).</p> </div> <details class=example> <summary>Example: catch a <code>parse_error</code> exception</summary> <p>The following code shows how a <code>parse_error</code> exception can be caught.</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>
@@ -139,7 +139,7 @@ byte position of error: 8
</code></pre></div> <div class=highlight><pre><span></span><code>[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing CBOR string: invalid string: ill-formed UTF-8 byte
</code></pre></div></p> </div> <h3 id=jsonexceptionparse_error114>json.exception.parse_error.114<a class=headerlink href=#jsonexceptionparse_error114 title="Permanent link">&para;</a></h3> <p>The parsing of the corresponding <abbr title="Binary JSON">BSON</abbr> record type is not implemented (yet).</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.parse_error.114] parse error at byte 5: Unsupported BSON record type 0xFF
</code></pre></div> </div> <h3 id=jsonexceptionparse_error115>json.exception.parse_error.115<a class=headerlink href=#jsonexceptionparse_error115 title="Permanent link">&para;</a></h3> <p>A <abbr title="Universal Binary JSON">UBJSON</abbr> high-precision number could not be parsed.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A
</code></pre></div> </div> <h2 id=iterator-errors>Iterator errors<a class=headerlink href=#iterator-errors title="Permanent link">&para;</a></h2> <p>This exception is thrown if iterators passed to a library function do not match the expected semantics.</p> <p>Exceptions have ids 2xx.</p> <details class=example> <summary>Example</summary> <p>The following code shows how an <code>invalid_iterator</code> exception can be caught.</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> </div> <h2 id=iterator-errors>Iterator errors<a class=headerlink href=#iterator-errors title="Permanent link">&para;</a></h2> <p>This exception is thrown if iterators passed to a library function do not match the expected semantics.</p> <p>Exceptions have ids 2xx.</p> <details class=example> <summary>Example: catch an <code>invalid_iterator</code> exception</summary> <p>The following code shows how an <code>invalid_iterator</code> exception can be caught.</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>
@@ -163,11 +163,11 @@ byte position of error: 8
</code></pre></div> <p>Output:</p> <div class=highlight><pre><span></span><code>message: [json.exception.invalid_iterator.207] cannot use key() for non-object iterators
exception id: 207
</code></pre></div> </details> <h3 id=jsonexceptioninvalid_iterator201>json.exception.invalid_iterator.201<a class=headerlink href=#jsonexceptioninvalid_iterator201 title="Permanent link">&para;</a></h3> <p>The iterators passed to constructor <code>basic_json(InputIT first, InputIT last)</code> are not compatible, meaning they do not belong to the same container. Therefore, the range (<code>first</code>, <code>last</code>) is invalid.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.201] iterators are not compatible
</code></pre></div> </div> <h3 id=jsonexceptioninvalid_iterator202>json.exception.invalid_iterator.202<a class=headerlink href=#jsonexceptioninvalid_iterator202 title="Permanent link">&para;</a></h3> <p>In the <a href=../../api/basic_json/erase/ >erase</a> or insert function, the passed iterator <code>pos</code> does not belong to the <abbr title="JavaScript Object Notation">JSON</abbr> value for which the function was called. It hence does not define a valid position for the deletion/insertion.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.202] iterator does not fit current value
</code></pre></div> </div> <h3 id=jsonexceptioninvalid_iterator202>json.exception.invalid_iterator.202<a class=headerlink href=#jsonexceptioninvalid_iterator202 title="Permanent link">&para;</a></h3> <p>In the <a href=../../api/basic_json/erase/ >erase</a> or <a href=../../api/basic_json/insert/ >insert</a> function, the passed iterator <code>pos</code> does not belong to the <abbr title="JavaScript Object Notation">JSON</abbr> value for which the function was called. It hence does not define a valid position for the deletion/insertion.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.202] iterator does not fit current value
</code></pre></div> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.202] iterators first and last must point to objects
</code></pre></div></p> </div> <h3 id=jsonexceptioninvalid_iterator203>json.exception.invalid_iterator.203<a class=headerlink href=#jsonexceptioninvalid_iterator203 title="Permanent link">&para;</a></h3> <p>Either iterator passed to function <a href=../../api/basic_json/erase/ ><code>erase(IteratorType first, IteratorType last</code>)</a> does not belong to the <abbr title="JavaScript Object Notation">JSON</abbr> value from which values shall be erased. It hence does not define a valid range to delete values from.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.203] iterators do not fit current value
</code></pre></div> </div> <h3 id=jsonexceptioninvalid_iterator204>json.exception.invalid_iterator.204<a class=headerlink href=#jsonexceptioninvalid_iterator204 title="Permanent link">&para;</a></h3> <p>When an iterator range for a primitive type (number, boolean, or string) is passed to a constructor or an <a href=../../api/basic_json/erase/ >erase</a> function, this range has to be exactly (<code>begin(),</code> <code>end()),</code> because this is the only way the single stored value is expressed. All other ranges are invalid.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.204] iterators out of range
</code></pre></div> </div> <h3 id=jsonexceptioninvalid_iterator205>json.exception.invalid_iterator.205<a class=headerlink href=#jsonexceptioninvalid_iterator205 title="Permanent link">&para;</a></h3> <p>When an iterator for a primitive type (number, boolean, or string) is passed to an <a href=../../api/basic_json/erase/ >erase</a> function, the iterator has to be the <code>begin()</code> iterator, because it is the only way to address the stored value. All other iterators are invalid.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.205] iterator out of range
</code></pre></div> </div> <h3 id=jsonexceptioninvalid_iterator205>json.exception.invalid_iterator.205<a class=headerlink href=#jsonexceptioninvalid_iterator205 title="Permanent link">&para;</a></h3> <p>When an iterator for a primitive type (number, boolean, or string) is passed to an <a href=../../api/basic_json/erase/ >erase</a> function, the iterator has to be the <a href=../../api/basic_json/begin/ ><code>begin()</code></a> iterator, because it is the only way to address the stored value. All other iterators are invalid.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.205] iterator out of range
</code></pre></div> </div> <h3 id=jsonexceptioninvalid_iterator206>json.exception.invalid_iterator.206<a class=headerlink href=#jsonexceptioninvalid_iterator206 title="Permanent link">&para;</a></h3> <p>The iterators passed to constructor <code>basic_json(InputIT first, InputIT last)</code> belong to a <abbr title="JavaScript Object Notation">JSON</abbr> null value and hence to not define a valid range.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.206] cannot construct with iterators from null
</code></pre></div> </div> <h3 id=jsonexceptioninvalid_iterator207>json.exception.invalid_iterator.207<a class=headerlink href=#jsonexceptioninvalid_iterator207 title="Permanent link">&para;</a></h3> <p>The <code>key()</code> member function can only be used on iterators belonging to a <abbr title="JavaScript Object Notation">JSON</abbr> object, because other types do not have a concept of a key.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.207] cannot use key() for non-object iterators
</code></pre></div> </div> <h3 id=jsonexceptioninvalid_iterator208>json.exception.invalid_iterator.208<a class=headerlink href=#jsonexceptioninvalid_iterator208 title="Permanent link">&para;</a></h3> <p>The <code>operator[]</code> to specify a concrete offset cannot be used on iterators belonging to a <abbr title="JavaScript Object Notation">JSON</abbr> object, because <abbr title="JavaScript Object Notation">JSON</abbr> objects are unordered.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.208] cannot use operator[] for object iterators
@@ -176,8 +176,8 @@ exception id: 207
</code></pre></div> </div> <h3 id=jsonexceptioninvalid_iterator211>json.exception.invalid_iterator.211<a class=headerlink href=#jsonexceptioninvalid_iterator211 title="Permanent link">&para;</a></h3> <p>The iterator range passed to the insert function must not be a subrange of the container to insert to.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.211] passed iterators may not belong to container
</code></pre></div> </div> <h3 id=jsonexceptioninvalid_iterator212>json.exception.invalid_iterator.212<a class=headerlink href=#jsonexceptioninvalid_iterator212 title="Permanent link">&para;</a></h3> <p>When two iterators are compared, they must belong to the same container.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.212] cannot compare iterators of different containers
</code></pre></div> </div> <h3 id=jsonexceptioninvalid_iterator213>json.exception.invalid_iterator.213<a class=headerlink href=#jsonexceptioninvalid_iterator213 title="Permanent link">&para;</a></h3> <p>The order of object iterators cannot be compared, because <abbr title="JavaScript Object Notation">JSON</abbr> objects are unordered.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.213] cannot compare order of object iterators
</code></pre></div> </div> <h3 id=jsonexceptioninvalid_iterator214>json.exception.invalid_iterator.214<a class=headerlink href=#jsonexceptioninvalid_iterator214 title="Permanent link">&para;</a></h3> <p>Cannot retrieve value from iterator: The iterator either refers to a null value, or it refers to a primitive type (number, boolean, or string), but does not match the iterator returned by <code>begin()</code>.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.214] cannot get value
</code></pre></div> </div> <h2 id=type-errors>Type errors<a class=headerlink href=#type-errors title="Permanent link">&para;</a></h2> <p>This exception is thrown in case of a type error; that is, a library function is executed on a <abbr title="JavaScript Object Notation">JSON</abbr> value whose type does not match the expected semantics.</p> <p>Exceptions have ids 3xx.</p> <details class=example> <summary>Example</summary> <p>The following code shows how a <code>type_error</code> exception can be caught.</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> </div> <h3 id=jsonexceptioninvalid_iterator214>json.exception.invalid_iterator.214<a class=headerlink href=#jsonexceptioninvalid_iterator214 title="Permanent link">&para;</a></h3> <p>Cannot retrieve value from iterator: The iterator either refers to a null value, or it refers to a primitive type (number, boolean, or string), but does not match the iterator returned by <a href=../../api/basic_json/begin/ ><code>begin()</code></a>.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.invalid_iterator.214] cannot get value
</code></pre></div> </div> <h2 id=type-errors>Type errors<a class=headerlink href=#type-errors title="Permanent link">&para;</a></h2> <p>This exception is thrown in case of a type error; that is, a library function is executed on a <abbr title="JavaScript Object Notation">JSON</abbr> value whose type does not match the expected semantics.</p> <p>Exceptions have ids 3xx.</p> <details class=example> <summary>Example: catch a <code>type_error</code> exception</summary> <p>The following code shows how a <code>type_error</code> exception can be caught.</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>
@@ -204,26 +204,26 @@ exception id: 308
</code></pre></div> <div class=highlight><pre><span></span><code>[json.exception.type_error.302] type must be string, but is object
</code></pre></div></p> </div> <h3 id=jsonexceptiontype_error303>json.exception.type_error.303<a class=headerlink href=#jsonexceptiontype_error303 title="Permanent link">&para;</a></h3> <p>To retrieve a reference to a value stored in a <code>basic_json</code> object with <code>get_ref</code>, the type of the reference must match the value type. For instance, for a <abbr title="JavaScript Object Notation">JSON</abbr> array, the <code>ReferenceType</code> must be <code>array_t &amp;</code>.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object
</code></pre></div> <div class=highlight><pre><span></span><code>[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
</code></pre></div></p> </div> <h3 id=jsonexceptiontype_error304>json.exception.type_error.304<a class=headerlink href=#jsonexceptiontype_error304 title="Permanent link">&para;</a></h3> <p>The <code>at()</code> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>[json.exception.type_error.304] cannot use at() with string
</code></pre></div></p> </div> <h3 id=jsonexceptiontype_error304>json.exception.type_error.304<a class=headerlink href=#jsonexceptiontype_error304 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/at/ ><code>at()</code></a> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>[json.exception.type_error.304] cannot use at() with string
</code></pre></div> <div class=highlight><pre><span></span><code>[json.exception.type_error.304] cannot use at() with number
</code></pre></div></p> </div> <h3 id=jsonexceptiontype_error305>json.exception.type_error.305<a class=headerlink href=#jsonexceptiontype_error305 title="Permanent link">&para;</a></h3> <p>The <code>operator[]</code> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>[json.exception.type_error.305] cannot use operator[] with a string argument with array
</code></pre></div></p> </div> <h3 id=jsonexceptiontype_error305>json.exception.type_error.305<a class=headerlink href=#jsonexceptiontype_error305 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/operator%5B%5D/ ><code>operator[]</code></a> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>[json.exception.type_error.305] cannot use operator[] with a string argument with array
</code></pre></div> <div class=highlight><pre><span></span><code>[json.exception.type_error.305] cannot use operator[] with a numeric argument with object
</code></pre></div></p> </div> <h3 id=jsonexceptiontype_error306>json.exception.type_error.306<a class=headerlink href=#jsonexceptiontype_error306 title="Permanent link">&para;</a></h3> <p>The <code>value()</code> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.306] cannot use value() with number
</code></pre></div></p> </div> <h3 id=jsonexceptiontype_error306>json.exception.type_error.306<a class=headerlink href=#jsonexceptiontype_error306 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/value/ ><code>value()</code></a> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.306] cannot use value() with number
</code></pre></div> </div> <h3 id=jsonexceptiontype_error307>json.exception.type_error.307<a class=headerlink href=#jsonexceptiontype_error307 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/erase/ ><code>erase()</code></a> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.307] cannot use erase() with string
</code></pre></div> </div> <h3 id=jsonexceptiontype_error308>json.exception.type_error.308<a class=headerlink href=#jsonexceptiontype_error308 title="Permanent link">&para;</a></h3> <p>The <code>push_back()</code> and <code>operator+=</code> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.308] cannot use push_back() with string
</code></pre></div> </div> <h3 id=jsonexceptiontype_error309>json.exception.type_error.309<a class=headerlink href=#jsonexceptiontype_error309 title="Permanent link">&para;</a></h3> <p>The <code>insert()</code> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>[json.exception.type_error.309] cannot use insert() with array
</code></pre></div> </div> <h3 id=jsonexceptiontype_error308>json.exception.type_error.308<a class=headerlink href=#jsonexceptiontype_error308 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/push_back/ ><code>push_back()</code></a> and <a href=../../api/basic_json/operator%2B%3D/ ><code>operator+=</code></a> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.308] cannot use push_back() with string
</code></pre></div> </div> <h3 id=jsonexceptiontype_error309>json.exception.type_error.309<a class=headerlink href=#jsonexceptiontype_error309 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/insert/ ><code>insert()</code></a> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>[json.exception.type_error.309] cannot use insert() with array
</code></pre></div> <div class=highlight><pre><span></span><code>[json.exception.type_error.309] cannot use insert() with number
</code></pre></div></p> </div> <h3 id=jsonexceptiontype_error310>json.exception.type_error.310<a class=headerlink href=#jsonexceptiontype_error310 title="Permanent link">&para;</a></h3> <p>The <code>swap()</code> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.310] cannot use swap() with number
</code></pre></div> </div> <h3 id=jsonexceptiontype_error311>json.exception.type_error.311<a class=headerlink href=#jsonexceptiontype_error311 title="Permanent link">&para;</a></h3> <p>The <code>emplace()</code> and <code>emplace_back()</code> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>[json.exception.type_error.311] cannot use emplace() with number
</code></pre></div></p> </div> <h3 id=jsonexceptiontype_error310>json.exception.type_error.310<a class=headerlink href=#jsonexceptiontype_error310 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/swap/ ><code>swap()</code></a> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.310] cannot use swap() with number
</code></pre></div> </div> <h3 id=jsonexceptiontype_error311>json.exception.type_error.311<a class=headerlink href=#jsonexceptiontype_error311 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/emplace/ ><code>emplace()</code></a> and <a href=../../api/basic_json/emplace_back/ ><code>emplace_back()</code></a> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>[json.exception.type_error.311] cannot use emplace() with number
</code></pre></div> <div class=highlight><pre><span></span><code>[json.exception.type_error.311] cannot use emplace_back() with number
</code></pre></div></p> </div> <h3 id=jsonexceptiontype_error312>json.exception.type_error.312<a class=headerlink href=#jsonexceptiontype_error312 title="Permanent link">&para;</a></h3> <p>The <code>update()</code> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.312] cannot use update() with array
</code></pre></div> </div> <h3 id=jsonexceptiontype_error313>json.exception.type_error.313<a class=headerlink href=#jsonexceptiontype_error313 title="Permanent link">&para;</a></h3> <p>The <code>unflatten</code> function converts an object whose keys are <abbr title="JavaScript Object Notation">JSON</abbr> Pointers back into an arbitrary nested <abbr title="JavaScript Object Notation">JSON</abbr> value. The <abbr title="JavaScript Object Notation">JSON</abbr> Pointers must not overlap, because then the resulting value would not be well-defined.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.313] invalid value to unflatten
</code></pre></div> </div> <h3 id=jsonexceptiontype_error314>json.exception.type_error.314<a class=headerlink href=#jsonexceptiontype_error314 title="Permanent link">&para;</a></h3> <p>The <code>unflatten</code> function only works for an object whose keys are <abbr title="JavaScript Object Notation">JSON</abbr> Pointers.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <p>Calling <code>unflatten()</code> on an array <code class=highlight><span class=p>[</span><span class=mi>1</span><span class=p>,</span><span class=mi>2</span><span class=p>,</span><span class=mi>3</span><span class=p>]</span></code>:</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.314] only objects can be unflattened
</code></pre></div> </div> <h3 id=jsonexceptiontype_error315>json.exception.type_error.315<a class=headerlink href=#jsonexceptiontype_error315 title="Permanent link">&para;</a></h3> <p>The <code>unflatten()</code> function only works for an object whose keys are <abbr title="JavaScript Object Notation">JSON</abbr> Pointers and whose values are primitive.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <p>Calling <code>unflatten()</code> on an object <code class=highlight><span class=p>{</span><span class=s2>"/1"</span><span class=p>,</span><span class=w> </span><span class=p>[</span><span class=mi>1</span><span class=p>,</span><span class=mi>2</span><span class=p>,</span><span class=mi>3</span><span class=p>]}</span></code>:</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.315] values in object must be primitive
</code></pre></div> </div> <h3 id=jsonexceptiontype_error316>json.exception.type_error.316<a class=headerlink href=#jsonexceptiontype_error316 title="Permanent link">&para;</a></h3> <p>The <code>dump()</code> function only works with <abbr title="Unicode Transformation Format">UTF</abbr>-8 encoded strings; that is, if you assign a <code>std::string</code> to a <abbr title="JavaScript Object Notation">JSON</abbr> value, make sure it is <abbr title="Unicode Transformation Format">UTF</abbr>-8 encoded.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <p>Calling <code>dump()</code> on a <abbr title="JavaScript Object Notation">JSON</abbr> value containing an <abbr title="International Organization for Standardization">ISO</abbr> 8859-1 encoded string: <div class=highlight><pre><span></span><code>[json.exception.type_error.316] invalid UTF-8 byte at index 15: 0x6F
</code></pre></div></p> </div> <h3 id=jsonexceptiontype_error312>json.exception.type_error.312<a class=headerlink href=#jsonexceptiontype_error312 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/update/ ><code>update()</code></a> member functions can only be executed for certain <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.312] cannot use update() with array
</code></pre></div> </div> <h3 id=jsonexceptiontype_error313>json.exception.type_error.313<a class=headerlink href=#jsonexceptiontype_error313 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/unflatten/ ><code>unflatten()</code></a> function converts an object whose keys are <abbr title="JavaScript Object Notation">JSON</abbr> Pointers back into an arbitrary nested <abbr title="JavaScript Object Notation">JSON</abbr> value. The <abbr title="JavaScript Object Notation">JSON</abbr> Pointers must not overlap, because then the resulting value would not be well-defined.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.313] invalid value to unflatten
</code></pre></div> </div> <h3 id=jsonexceptiontype_error314>json.exception.type_error.314<a class=headerlink href=#jsonexceptiontype_error314 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/unflatten/ ><code>unflatten()</code></a> function only works for an object whose keys are <abbr title="JavaScript Object Notation">JSON</abbr> Pointers.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <p>Calling <code>unflatten()</code> on an array <code class=highlight><span class=p>[</span><span class=mi>1</span><span class=p>,</span><span class=mi>2</span><span class=p>,</span><span class=mi>3</span><span class=p>]</span></code>:</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.314] only objects can be unflattened
</code></pre></div> </div> <h3 id=jsonexceptiontype_error315>json.exception.type_error.315<a class=headerlink href=#jsonexceptiontype_error315 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/unflatten/ ><code>unflatten()</code></a> function only works for an object whose keys are <abbr title="JavaScript Object Notation">JSON</abbr> Pointers and whose values are primitive.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <p>Calling <code>unflatten()</code> on an object <code class=highlight><span class=p>{</span><span class=s2>"/1"</span><span class=p>,</span><span class=w> </span><span class=p>[</span><span class=mi>1</span><span class=p>,</span><span class=mi>2</span><span class=p>,</span><span class=mi>3</span><span class=p>]}</span></code>:</p> <div class=highlight><pre><span></span><code>[json.exception.type_error.315] values in object must be primitive
</code></pre></div> </div> <h3 id=jsonexceptiontype_error316>json.exception.type_error.316<a class=headerlink href=#jsonexceptiontype_error316 title="Permanent link">&para;</a></h3> <p>The <a href=../../api/basic_json/dump/ ><code>dump()</code></a> function only works with <abbr title="Unicode Transformation Format">UTF</abbr>-8 encoded strings; that is, if you assign a <code>std::string</code> to a <abbr title="JavaScript Object Notation">JSON</abbr> value, make sure it is <abbr title="Unicode Transformation Format">UTF</abbr>-8 encoded. See the <abbr title="Frequently Asked Questions">FAQ</abbr> entry on <a href=../faq/#serializing-untrusted-or-invalid-utf-8>serializing untrusted or invalid <abbr title="Unicode Transformation Format">UTF</abbr>-8</a> for background and the recommended fix.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <p>Calling <code>dump()</code> on a <abbr title="JavaScript Object Notation">JSON</abbr> value containing an <abbr title="International Organization for Standardization">ISO</abbr> 8859-1 encoded string: <div class=highlight><pre><span></span><code>[json.exception.type_error.316] invalid UTF-8 byte at index 15: 0x6F
</code></pre></div></p> </div> <div class="admonition tip"> <p class=admonition-title>Tip</p> <ul> <li>Store the source file with <abbr title="Unicode Transformation Format">UTF</abbr>-8 encoding.</li> <li>Pass an error handler as last parameter to the <code>dump()</code> function to avoid this exception:<ul> <li><code>json::error_handler_t::replace</code> will replace invalid bytes sequences with <code>U+FFFD</code> </li> <li><code>json::error_handler_t::ignore</code> will silently ignore invalid byte sequences</li> </ul> </li> </ul> </div> <h3 id=jsonexceptiontype_error317>json.exception.type_error.317<a class=headerlink href=#jsonexceptiontype_error317 title="Permanent link">&para;</a></h3> <p>The dynamic type of the object cannot be represented in the requested serialization format (e.g., a raw <code>true</code> or <code>null</code> <abbr title="JavaScript Object Notation">JSON</abbr> object cannot be serialized to <abbr title="Binary JSON">BSON</abbr>)</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p>Serializing <code class=highlight><span class=kc>null</span></code> to <abbr title="Binary JSON">BSON</abbr>: <div class=highlight><pre><span></span><code>[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is null
</code></pre></div> Serializing <code class=highlight><span class=p>[</span><span class=mi>1</span><span class=p>,</span><span class=mi>2</span><span class=p>,</span><span class=mi>3</span><span class=p>]</span></code> to <abbr title="Binary JSON">BSON</abbr>: <div class=highlight><pre><span></span><code>[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is array
</code></pre></div></p> </div> <div class="admonition tip"> <p class=admonition-title>Tip</p> <p>Encapsulate the <abbr title="JavaScript Object Notation">JSON</abbr> value in an object. That is, instead of serializing <code class=highlight><span class=kc>true</span></code>, serialize <code class=highlight><span class=p>{</span><span class=nt>"value"</span><span class=p>:</span><span class=w> </span><span class=kc>true</span><span class=p>}</span></code></p> </div> <h2 id=out-of-range>Out of range<a class=headerlink href=#out-of-range title="Permanent link">&para;</a></h2> <p>This exception is thrown in case a library function is called on an input parameter that exceeds the expected range, for instance, in the case of array indices or nonexisting object keys.</p> <p>Exceptions have ids 4xx.</p> <details class=example> <summary>Example</summary> <p>The following code shows how an <code>out_of_range</code> exception can be caught.</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> </div> <div class="admonition tip"> <p class=admonition-title>Tip</p> <p>Encapsulate the <abbr title="JavaScript Object Notation">JSON</abbr> value in an object. That is, instead of serializing <code class=highlight><span class=kc>true</span></code>, serialize <code class=highlight><span class=p>{</span><span class=nt>"value"</span><span class=p>:</span><span class=w> </span><span class=kc>true</span><span class=p>}</span></code></p> </div> <h2 id=out-of-range>Out of range<a class=headerlink href=#out-of-range title="Permanent link">&para;</a></h2> <p>This exception is thrown in case a library function is called on an input parameter that exceeds the expected range, for instance, in the case of array indices or nonexisting object keys.</p> <p>Exceptions have ids 4xx.</p> <details class=example> <summary>Example: catch an <code>out_of_range</code> exception</summary> <p>The following code shows how an <code>out_of_range</code> exception can be caught.</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>
@@ -259,12 +259,12 @@ exception id: 401
</code></pre></div> </div> <h3 id=jsonexceptionout_of_range410>json.exception.out_of_range.410<a class=headerlink href=#jsonexceptionout_of_range410 title="Permanent link">&para;</a></h3> <p>This exception is thrown when an undefined value is used with <a href=../../api/macros/nlohmann_json_serialize_enum_strict/ ><code>NLOHMANN_JSON_SERIALIZE_ENUM_STRICT</code></a>, or when an array index in a <abbr title="JavaScript Object Notation">JSON</abbr> pointer exceeds the range of <code>size_type</code> (e.g., on 32-bit platforms).</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>enum value out of range
array index 18446744073709551616 exceeds size_type
</code></pre></div> </div> <h3 id=jsonexceptionout_of_range411>json.exception.out_of_range.411<a class=headerlink href=#jsonexceptionout_of_range411 title="Permanent link">&para;</a></h3> <p>A <abbr title="JavaScript Object Notation">JSON</abbr> Patch <code>add</code> operation cannot be applied because the target location's parent is neither an object nor an array. Per <a href="https://datatracker.ietf.org/doc/html/rfc6902"><abbr title="Request for Comments">RFC</abbr> 6902</a>, an <code>add</code> target must reference a member of an existing object or an element of an existing array; a primitive value (string, number, boolean, etc.) cannot receive a new member or element.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>cannot add value: the JSON Patch 'add' target's parent is of type string, but must be an object or array
</code></pre></div> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This exception was added in version 3.13.0. Before that, this situation hit an internal assertion (aborting the program in debug builds) or was silently ignored when assertions were disabled.</p> </div> <h3 id=jsonexceptionout_of_range412>json.exception.out_of_range.412<a class=headerlink href=#jsonexceptionout_of_range412 title="Permanent link">&para;</a></h3> <p><abbr title="Binary JSON">BSON</abbr> stores the length of documents, arrays, strings, and binary values in a signed 32-bit integer, and MessagePack stores the length of strings, binary values, arrays, and objects in at most an unsigned 32-bit integer. This exception is thrown when a value is too large to be described by such a length field.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>BSON length 2147483661 exceeds maximum of 2147483647
</code></pre></div> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This exception was 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>. Before that, this situation hit an internal assertion (aborting the program in debug builds) or was silently ignored when assertions were disabled.</p> </div> <h3 id=jsonexceptionout_of_range412>json.exception.out_of_range.412<a class=headerlink href=#jsonexceptionout_of_range412 title="Permanent link">&para;</a></h3> <p><abbr title="Binary JSON">BSON</abbr> stores the length of documents, arrays, strings, and binary values in a signed 32-bit integer, and MessagePack stores the length of strings, binary values, arrays, and objects in at most an unsigned 32-bit integer. This exception is thrown when a value is too large to be described by such a length field.</p> <div class="admonition failure"> <p class=admonition-title>Example messages</p> <p><div class=highlight><pre><span></span><code>BSON length 2147483661 exceeds maximum of 2147483647
</code></pre></div> <div class=highlight><pre><span></span><code>MessagePack length 4294967296 exceeds maximum of 4294967295
</code></pre></div></p> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This exception was added in version 3.13.0. Before that, the <abbr title="Binary JSON">BSON</abbr> length was silently truncated, and <a href=../../api/basic_json/to_bson/ ><code>to_bson</code></a> produced documents with negative length prefixes that <a href=../../api/basic_json/from_bson/ ><code>from_bson</code></a> rejected; <a href=../../api/basic_json/to_msgpack/ ><code>to_msgpack</code></a> wrote such a value without any length, producing output that could not be read back.</p> </div> <h3 id=jsonexceptionout_of_range413>json.exception.out_of_range.413<a class=headerlink href=#jsonexceptionout_of_range413 title="Permanent link">&para;</a></h3> <p>A <abbr title="JavaScript Object Notation">JSON</abbr> Patch <code>remove</code> operation cannot be applied because the target location's parent is neither an object nor an array. Per <a href="https://datatracker.ietf.org/doc/html/rfc6902"><abbr title="Request for Comments">RFC</abbr> 6902</a>, a <code>remove</code> target must reference a member of an existing object or an element of an existing array; a primitive value (string, number, boolean, etc.) or <code>null</code> has no members or elements to remove.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>cannot remove value: the JSON Patch 'remove' target's parent is of type number, but must be an object or array
</code></pre></div> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This exception was added in version 3.13.0. Before that, this situation was silently ignored (the <code>remove</code> operation had no effect).</p> </div> <h3 id=jsonexceptionout_of_range414>json.exception.out_of_range.414<a class=headerlink href=#jsonexceptionout_of_range414 title="Permanent link">&para;</a></h3> <p>A <abbr title="JavaScript Object Notation">JSON</abbr> Patch <code>move</code> operation's <code>"from"</code> location is a proper prefix of its <code>"path"</code> location. Per <a href="https://datatracker.ietf.org/doc/html/rfc6902"><abbr title="Request for Comments">RFC</abbr> 6902</a> (section 4.4), a location cannot be moved into one of its own children.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>cannot move value: 'from' path '/0' is a proper prefix of 'path' '/0/0'
</code></pre></div> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This exception was added in version 3.13.0. Before that, this situation could succeed with a corrupted result: for an array target, removing the "from" element before the "add" step shifted subsequent indices, so "path" silently re-resolved to a different element than intended.</p> </div> <h3 id=jsonexceptionout_of_range415>json.exception.out_of_range.415<a class=headerlink href=#jsonexceptionout_of_range415 title="Permanent link">&para;</a></h3> <p>MessagePack's ext type and <abbr title="Binary JSON">BSON</abbr>'s binary subtype are each stored in a single byte. This exception is thrown when serializing a <a href=../../api/byte_container_with_subtype/ ><code>byte_container_with_subtype</code></a> whose subtype exceeds 255.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.out_of_range.415] subtype 70000 is too large for the MessagePack ext type (max 255)
</code></pre></div> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This exception was added in version 3.13.0. Before that, subtypes above 255 were silently truncated modulo 256 instead of raising an error.</p> </div> <h2 id=further-exceptions>Further exceptions<a class=headerlink href=#further-exceptions title="Permanent link">&para;</a></h2> <p>This exception is thrown in case of errors that cannot be classified with the other exception types.</p> <p>Exceptions have ids 5xx.</p> <details class=example> <summary>Example</summary> <p>The following code shows how an <code>other_error</code> exception can be caught.</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> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This exception was 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>. Before that, the <abbr title="Binary JSON">BSON</abbr> length was silently truncated, and <a href=../../api/basic_json/to_bson/ ><code>to_bson</code></a> produced documents with negative length prefixes that <a href=../../api/basic_json/from_bson/ ><code>from_bson</code></a> rejected; <a href=../../api/basic_json/to_msgpack/ ><code>to_msgpack</code></a> wrote such a value without any length, producing output that could not be read back.</p> </div> <h3 id=jsonexceptionout_of_range413>json.exception.out_of_range.413<a class=headerlink href=#jsonexceptionout_of_range413 title="Permanent link">&para;</a></h3> <p>A <abbr title="JavaScript Object Notation">JSON</abbr> Patch <code>remove</code> operation cannot be applied because the target location's parent is neither an object nor an array. Per <a href="https://datatracker.ietf.org/doc/html/rfc6902"><abbr title="Request for Comments">RFC</abbr> 6902</a>, a <code>remove</code> target must reference a member of an existing object or an element of an existing array; a primitive value (string, number, boolean, etc.) or <code>null</code> has no members or elements to remove.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>cannot remove value: the JSON Patch 'remove' target's parent is of type number, but must be an object or array
</code></pre></div> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This exception was 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>. Before that, this situation was silently ignored (the <code>remove</code> operation had no effect).</p> </div> <h3 id=jsonexceptionout_of_range414>json.exception.out_of_range.414<a class=headerlink href=#jsonexceptionout_of_range414 title="Permanent link">&para;</a></h3> <p>A <abbr title="JavaScript Object Notation">JSON</abbr> Patch <code>move</code> operation's <code>"from"</code> location is a proper prefix of its <code>"path"</code> location. Per <a href="https://datatracker.ietf.org/doc/html/rfc6902"><abbr title="Request for Comments">RFC</abbr> 6902</a> (section 4.4), a location cannot be moved into one of its own children.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>cannot move value: 'from' path '/0' is a proper prefix of 'path' '/0/0'
</code></pre></div> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This exception was 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>. Before that, this situation could succeed with a corrupted result: for an array target, removing the "from" element before the "add" step shifted subsequent indices, so "path" silently re-resolved to a different element than intended.</p> </div> <h3 id=jsonexceptionout_of_range415>json.exception.out_of_range.415<a class=headerlink href=#jsonexceptionout_of_range415 title="Permanent link">&para;</a></h3> <p>MessagePack's ext type and <abbr title="Binary JSON">BSON</abbr>'s binary subtype are each stored in a single byte. This exception is thrown when serializing a <a href=../../api/byte_container_with_subtype/ ><code>byte_container_with_subtype</code></a> whose subtype exceeds 255.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.out_of_range.415] subtype 70000 is too large for the MessagePack ext type (max 255)
</code></pre></div> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This exception was 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>. Before that, subtypes above 255 were silently truncated modulo 256 instead of raising an error.</p> </div> <h2 id=further-exceptions>Further exceptions<a class=headerlink href=#further-exceptions title="Permanent link">&para;</a></h2> <p>This exception is thrown in case of errors that cannot be classified with the other exception types.</p> <p>Exceptions have ids 5xx.</p> <details class=example> <summary>Example: catch an <code>other_error</code> exception</summary> <p>The following code shows how an <code>other_error</code> exception can be caught.</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>
@@ -298,4 +298,4 @@ array index 18446744073709551616 exceeds size_type
exception id: 501
</code></pre></div> </details> <h3 id=jsonexceptionother_error501>json.exception.other_error.501<a class=headerlink href=#jsonexceptionother_error501 title="Permanent link">&para;</a></h3> <p>A <abbr title="JavaScript Object Notation">JSON</abbr> Patch operation 'test' failed. The unsuccessful operation is also printed.</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <p>Executing <code class=highlight><span class=p>{</span><span class=nt>"op"</span><span class=p>:</span><span class=s2>"test"</span><span class=p>,</span><span class=w> </span><span class=nt>"path"</span><span class=p>:</span><span class=s2>"/baz"</span><span class=p>,</span><span class=w> </span><span class=nt>"value"</span><span class=p>:</span><span class=s2>"bar"</span><span class=p>}</span></code> on <code class=highlight><span class=p>{</span><span class=nt>"baz"</span><span class=p>:</span><span class=w> </span><span class=s2>"qux"</span><span class=p>}</span></code>:</p> <div class=highlight><pre><span></span><code>[json.exception.other_error.501] unsuccessful: {"op":"test","path":"/baz","value":"bar"}
</code></pre></div> </div> <h3 id=jsonexceptionother_error502>json.exception.other_error.502<a class=headerlink href=#jsonexceptionother_error502 title="Permanent link">&para;</a></h3> <p><a href=../../api/basic_json/to_ubjson/ ><code>to_ubjson</code></a> and <a href=../../api/basic_json/to_bjdata/ ><code>to_bjdata</code></a> were called with <code>use_type = true</code> but <code>use_size = false</code>. <abbr title="Universal Binary JSON">UBJSON</abbr> requires a size marker (<code>#</code>) after a type marker (<code>$</code>).</p> <div class="admonition failure"> <p class=admonition-title>Example message</p> <div class=highlight><pre><span></span><code>[json.exception.other_error.502] use_type requires use_size = true
</code></pre></div> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This exception was added in version 3.13.0. Before that, debug builds aborted on an assertion and release builds wrote a <code>$</code> marker without <code>#</code>, which <a href=../../api/basic_json/from_ubjson/ ><code>from_ubjson</code></a> then rejected.</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:23:55 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.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9z"/></svg> </a> <a href="https://www.xing.com/profile/Niels_Lohmann" target="_blank" rel="noopener" title="www.xing.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 384 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) CopyrigLine truncated
</code></pre></div> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This exception was 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>. Before that, debug builds aborted on an assertion and release builds wrote a <code>$</code> marker without <code>#</code>, which <a href=../../api/basic_json/from_ubjson/ ><code>from_ubjson</code></a> then rejected.</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.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.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9z"/></svg> </a> <a href="https://www.xing.com/profile/Niels_Lohmann" target="_blank" rel="noopener" title="www.xing.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 384 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.coLine truncated
+29 -29
View File
@@ -41,7 +41,7 @@ Exceptions are used widely within the library. They can, however, be switched of
Note that [`JSON_THROW_USER`](https://json.nlohmann.me/api/macros/json_throw_user/index.md) should leave the current scope (e.g., by throwing or aborting), as continuing after it may yield undefined behavior.
Example
Example: switch off exceptions and log errors before aborting
The code below switches off exceptions and creates a log entry with a detailed error message in case of errors.
@@ -67,7 +67,7 @@ See [documentation of `JSON_TRY_USER`, `JSON_CATCH_USER` and `JSON_THROW_USER`](
Exceptions in the library are thrown in the local context of the JSON value they are detected. This makes detailed diagnostics messages, and hence debugging, difficult.
Example
Example: standard diagnostic message
```
#include <iostream>
@@ -104,7 +104,7 @@ To create better diagnostics messages, each JSON value needs a pointer to its pa
As this global context comes at the price of storing one additional pointer per JSON value and runtime overhead to maintain the parent relation, extended diagnostics are disabled by default. They can, however, be enabled by defining the preprocessor symbol [`JSON_DIAGNOSTICS`](https://json.nlohmann.me/api/macros/json_diagnostics/index.md) to `1` before including `json.hpp`.
Example
Example: extended diagnostic message with `JSON_DIAGNOSTICS`
```
#include <iostream>
@@ -153,7 +153,7 @@ Member `byte` holds the byte index of the last read character in the input file.
For an input with n bytes, 1 is the index of the first character and n+1 is the index of the terminating null byte or the end of file. This also holds true when reading a byte vector (CBOR or MessagePack).
Example
Example: catch a `parse_error` exception
The following code shows how a `parse_error` exception can be caught.
@@ -461,7 +461,7 @@ This exception is thrown if iterators passed to a library function do not match
Exceptions have ids 2xx.
Example
Example: catch an `invalid_iterator` exception
The following code shows how an `invalid_iterator` exception can be caught.
@@ -508,7 +508,7 @@ Example message
### json.exception.invalid_iterator.202
In the [erase](https://json.nlohmann.me/api/basic_json/erase/index.md) or insert function, the passed iterator `pos` does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion.
In the [erase](https://json.nlohmann.me/api/basic_json/erase/index.md) or [insert](https://json.nlohmann.me/api/basic_json/insert/index.md) function, the passed iterator `pos` does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion.
Example messages
@@ -542,7 +542,7 @@ Example message
### json.exception.invalid_iterator.205
When an iterator for a primitive type (number, boolean, or string) is passed to an [erase](https://json.nlohmann.me/api/basic_json/erase/index.md) function, the iterator has to be the `begin()` iterator, because it is the only way to address the stored value. All other iterators are invalid.
When an iterator for a primitive type (number, boolean, or string) is passed to an [erase](https://json.nlohmann.me/api/basic_json/erase/index.md) function, the iterator has to be the [`begin()`](https://json.nlohmann.me/api/basic_json/begin/index.md) iterator, because it is the only way to address the stored value. All other iterators are invalid.
Example message
@@ -632,7 +632,7 @@ Example message
### json.exception.invalid_iterator.214
Cannot retrieve value from iterator: The iterator either refers to a null value, or it refers to a primitive type (number, boolean, or string), but does not match the iterator returned by `begin()`.
Cannot retrieve value from iterator: The iterator either refers to a null value, or it refers to a primitive type (number, boolean, or string), but does not match the iterator returned by [`begin()`](https://json.nlohmann.me/api/basic_json/begin/index.md).
Example message
@@ -646,7 +646,7 @@ This exception is thrown in case of a type error; that is, a library function is
Exceptions have ids 3xx.
Example
Example: catch a `type_error` exception
The following code shows how a `type_error` exception can be caught.
@@ -720,7 +720,7 @@ Example messages
### json.exception.type_error.304
The `at()` member functions can only be executed for certain JSON types.
The [`at()`](https://json.nlohmann.me/api/basic_json/at/index.md) member functions can only be executed for certain JSON types.
Example messages
@@ -734,7 +734,7 @@ Example messages
### json.exception.type_error.305
The `operator[]` member functions can only be executed for certain JSON types.
The [`operator[]`](https://json.nlohmann.me/api/basic_json/operator%5B%5D/index.md) member functions can only be executed for certain JSON types.
Example messages
@@ -748,7 +748,7 @@ Example messages
### json.exception.type_error.306
The `value()` member functions can only be executed for certain JSON types.
The [`value()`](https://json.nlohmann.me/api/basic_json/value/index.md) member functions can only be executed for certain JSON types.
Example message
@@ -768,7 +768,7 @@ Example message
### json.exception.type_error.308
The `push_back()` and `operator+=` member functions can only be executed for certain JSON types.
The [`push_back()`](https://json.nlohmann.me/api/basic_json/push_back/index.md) and [`operator+=`](https://json.nlohmann.me/api/basic_json/operator%2B%3D/index.md) member functions can only be executed for certain JSON types.
Example message
@@ -778,7 +778,7 @@ Example message
### json.exception.type_error.309
The `insert()` member functions can only be executed for certain JSON types.
The [`insert()`](https://json.nlohmann.me/api/basic_json/insert/index.md) member functions can only be executed for certain JSON types.
Example messages
@@ -792,7 +792,7 @@ Example messages
### json.exception.type_error.310
The `swap()` member functions can only be executed for certain JSON types.
The [`swap()`](https://json.nlohmann.me/api/basic_json/swap/index.md) member functions can only be executed for certain JSON types.
Example message
@@ -802,7 +802,7 @@ Example message
### json.exception.type_error.311
The `emplace()` and `emplace_back()` member functions can only be executed for certain JSON types.
The [`emplace()`](https://json.nlohmann.me/api/basic_json/emplace/index.md) and [`emplace_back()`](https://json.nlohmann.me/api/basic_json/emplace_back/index.md) member functions can only be executed for certain JSON types.
Example messages
@@ -816,7 +816,7 @@ Example messages
### json.exception.type_error.312
The `update()` member functions can only be executed for certain JSON types.
The [`update()`](https://json.nlohmann.me/api/basic_json/update/index.md) member functions can only be executed for certain JSON types.
Example message
@@ -826,7 +826,7 @@ Example message
### json.exception.type_error.313
The `unflatten` function converts an object whose keys are JSON Pointers back into an arbitrary nested JSON value. The JSON Pointers must not overlap, because then the resulting value would not be well-defined.
The [`unflatten()`](https://json.nlohmann.me/api/basic_json/unflatten/index.md) function converts an object whose keys are JSON Pointers back into an arbitrary nested JSON value. The JSON Pointers must not overlap, because then the resulting value would not be well-defined.
Example message
@@ -836,7 +836,7 @@ Example message
### json.exception.type_error.314
The `unflatten` function only works for an object whose keys are JSON Pointers.
The [`unflatten()`](https://json.nlohmann.me/api/basic_json/unflatten/index.md) function only works for an object whose keys are JSON Pointers.
Example message
@@ -848,7 +848,7 @@ Calling `unflatten()` on an array `[1,2,3]`:
### json.exception.type_error.315
The `unflatten()` function only works for an object whose keys are JSON Pointers and whose values are primitive.
The [`unflatten()`](https://json.nlohmann.me/api/basic_json/unflatten/index.md) function only works for an object whose keys are JSON Pointers and whose values are primitive.
Example message
@@ -860,7 +860,7 @@ Calling `unflatten()` on an object `{"/1", [1,2,3]}`:
### json.exception.type_error.316
The `dump()` function only works with UTF-8 encoded strings; that is, if you assign a `std::string` to a JSON value, make sure it is UTF-8 encoded.
The [`dump()`](https://json.nlohmann.me/api/basic_json/dump/index.md) function only works with UTF-8 encoded strings; that is, if you assign a `std::string` to a JSON value, make sure it is UTF-8 encoded. See the FAQ entry on [serializing untrusted or invalid UTF-8](https://json.nlohmann.me/home/faq/#serializing-untrusted-or-invalid-utf-8) for background and the recommended fix.
Example message
@@ -905,7 +905,7 @@ This exception is thrown in case a library function is called on an input parame
Exceptions have ids 4xx.
Example
Example: catch an `out_of_range` exception
The following code shows how an `out_of_range` exception can be caught.
@@ -1065,7 +1065,7 @@ cannot add value: the JSON Patch 'add' target's parent is of type string, but mu
Note
This exception was added in version 3.13.0. Before that, this situation hit an internal assertion (aborting the program in debug builds) or was silently ignored when assertions were disabled.
This exception was added in version 3.13.0 unreleased. Before that, this situation hit an internal assertion (aborting the program in debug builds) or was silently ignored when assertions were disabled.
### json.exception.out_of_range.412
@@ -1083,7 +1083,7 @@ MessagePack length 4294967296 exceeds maximum of 4294967295
Note
This exception was added in version 3.13.0. Before that, the BSON length was silently truncated, and [`to_bson`](https://json.nlohmann.me/api/basic_json/to_bson/index.md) produced documents with negative length prefixes that [`from_bson`](https://json.nlohmann.me/api/basic_json/from_bson/index.md) rejected; [`to_msgpack`](https://json.nlohmann.me/api/basic_json/to_msgpack/index.md) wrote such a value without any length, producing output that could not be read back.
This exception was added in version 3.13.0 unreleased. Before that, the BSON length was silently truncated, and [`to_bson`](https://json.nlohmann.me/api/basic_json/to_bson/index.md) produced documents with negative length prefixes that [`from_bson`](https://json.nlohmann.me/api/basic_json/from_bson/index.md) rejected; [`to_msgpack`](https://json.nlohmann.me/api/basic_json/to_msgpack/index.md) wrote such a value without any length, producing output that could not be read back.
### json.exception.out_of_range.413
@@ -1097,7 +1097,7 @@ cannot remove value: the JSON Patch 'remove' target's parent is of type number,
Note
This exception was added in version 3.13.0. Before that, this situation was silently ignored (the `remove` operation had no effect).
This exception was added in version 3.13.0 unreleased. Before that, this situation was silently ignored (the `remove` operation had no effect).
### json.exception.out_of_range.414
@@ -1111,7 +1111,7 @@ cannot move value: 'from' path '/0' is a proper prefix of 'path' '/0/0'
Note
This exception was added in version 3.13.0. Before that, this situation could succeed with a corrupted result: for an array target, removing the "from" element before the "add" step shifted subsequent indices, so "path" silently re-resolved to a different element than intended.
This exception was added in version 3.13.0 unreleased. Before that, this situation could succeed with a corrupted result: for an array target, removing the "from" element before the "add" step shifted subsequent indices, so "path" silently re-resolved to a different element than intended.
### json.exception.out_of_range.415
@@ -1125,7 +1125,7 @@ Example message
Note
This exception was added in version 3.13.0. Before that, subtypes above 255 were silently truncated modulo 256 instead of raising an error.
This exception was added in version 3.13.0 unreleased. Before that, subtypes above 255 were silently truncated modulo 256 instead of raising an error.
## Further exceptions
@@ -1133,7 +1133,7 @@ This exception is thrown in case of errors that cannot be classified with the ot
Exceptions have ids 5xx.
Example
Example: catch an `other_error` exception
The following code shows how an `other_error` exception can be caught.
@@ -1201,4 +1201,4 @@ Example message
Note
This exception was added in version 3.13.0. Before that, debug builds aborted on an assertion and release builds wrote a `$` marker without `#`, which [`from_ubjson`](https://json.nlohmann.me/api/basic_json/from_ubjson/index.md) then rejected.
This exception was added in version 3.13.0 unreleased. Before that, debug builds aborted on an assertion and release builds wrote a `$` marker without `#`, which [`from_ubjson`](https://json.nlohmann.me/api/basic_json/from_ubjson/index.md) then rejected.