This commit is contained in:
nlohmann committed 2026-11-12 11:46:38 +00:00
1 parent 8ddeea7128
commit 5097c20962
516 files changed
+7306 -5984

No files matched your search

@@ -0,0 +1,72 @@
<!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=description content="JSON for Modern C++ is a header-only C++11 library that makes JSON a first-class data type."><meta name=author content="Niels Lohmann"><link href="https://json.nlohmann.me/api/macros/json_recursion_depth_limit/" rel="canonical"><link href=../json_precise_stream_position/ rel=prev><link href=../json_skip_library_version_check/ rel=next><link rel=icon href=../../../assets/images/favicon.png><meta name=generator content="mkdocs-1.6.1, mkdocs-material-9.8.0"><title>JSON_RECURSION_DEPTH_LIMIT - JSON for Modern C++</title><link rel=stylesheet href=../../../assets/stylesheets/main.57a0d79d.min.css><link rel=stylesheet href=../../../assets/stylesheets/palette.fb2fffe2.min.css><link rel=stylesheet href=../../../css/custom.css><link rel=stylesheet href=../../../css/brand.css><link rel=stylesheet href=../../../css/fig-sax.css><link rel=stylesheet href=../../../css/fig-jsonview.css><link rel=stylesheet href=../../../css/fig-exceptions.css><link rel=stylesheet href=../../../css/fig-pointer.css><link rel=stylesheet href=../../../css/fig-charts.css><link rel=stylesheet href=../../../css/fig-integration.css><link rel=stylesheet href=../../../css/fig-macros.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=custom data-md-color-accent=custom> <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=#json_recursion_depth_limit 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> <img src=../../../images/wordmark-header.svg alt=logo> </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> JSON_RECURSION_DEPTH_LIMIT </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=custom data-md-color-accent=custom 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=custom data-md-color-accent=custom 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=Line truncated
</code></pre></div> <p>This macro sets how many nesting levels the operations that walk a value recurse into on the call stack. Beyond that, they continue with an explicit stack on the heap. The value is an integer constant from <code>0</code> to <code>254</code>; the default is <code>128</code>.</p> <p>The operations are copying a value, comparing two values, serializing with <a href=../../basic_json/dump/ ><code>dump</code></a> or <a href=../../operator_ltlt/ ><code>operator&lt;&lt;</code></a>, hashing with <code>std::hash</code>, <a href=../../basic_json/merge_patch/ ><code>merge_patch</code></a>, <a href=../../basic_json/update/ ><code>update</code></a> with <code>merge_objects</code>, <a href=../../basic_json/diff/ ><code>diff</code></a>, <a href=../../basic_json/merge_diff/ ><code>merge_diff</code></a>, converting a value to another specialization of <code>basic_json</code>, destroying a value, and the binary writers <a href=../../basic_json/to_cbor/ ><code>to_cbor</code></a>, <a href=../../basic_json/to_msgpack/ ><code>to_msgpack</code></a>, <a href=../../basic_json/to_ubjson/ ><code>to_ubjson</code></a>, <a href=../../basic_json/to_bjdata/ ><code>to_bjdata</code></a>, and <a href=../../basic_json/to_bon8/ ><code>to_bon8</code></a>. They share this one limit; none has a limit of its own. Recursing is the fastest way to walk a value, but a value nested deeply enough would exhaust the call stack, so the library recurses only as far as the limit and finishes the levels below with an explicit stack. This is what makes all of them safe for untrusted input (see <a href=../../../features/parsing/untrusted_input/#nesting-depth>Nesting depth</a>). Parsing, the binary readers, <a href=../../basic_json/flatten/ ><code>flatten</code></a>, <a href=../../basic_json/unflatten/ ><code>unflatten</code></a>, and <a href=../../basic_json/to_bson/ ><code>to_bson</code></a> always use an explicit stack and do not depend on the macro. The lockstep comparison of two <a href=../../basic_json_view/ ><code>json_view</code></a> documents has a fixed bound of its own, 48 levels, and does not depend on it either.</p> <p>The call stack that these operations need grows with the limit: roughly <em>a few kilobytes plus a cost per level times the limit</em>, where the cost per level is up to about 2.3 KiB in an unoptimized and up to about 0.5 KiB in an optimized build (see <a href=#stack-needed>Stack needed</a>). The default of <code>128</code> levels is tuned for threads with ordinary stacks of a few hundred kilobytes or more. Set a lower limit if your threads have small stacks (RTOS tasks, fibers, threads of the musl C library, which has a default stack of 128 KiB), or a higher limit to trade stack for speed on deeply nested values.</p> <p>The macro changes only how much stack is used and how fast the operations are. It never changes a result: every operation returns the same value for every setting of the limit, for values nested less deeply than the limit as well as for values nested more deeply.</p> <h2 id=default-definition>Default definition<a class=headerlink href=#default-definition title="Permanent link">&para;</a></h2> <p>The default value is <code>128</code>.</p> <div class=highlight><pre><span></span><code><span class=cp>#define JSON_RECURSION_DEPTH_LIMIT 128</span>
</code></pre></div> <p>When the macro is not defined, the library defines it to its default value.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Allowed values</p> <p>The value must be an integer constant expression from <code>0</code> to <code>254</code>; any other value (a negative number, a number above <code>254</code>, a floating-point number such as <code>254.0</code>, or <code>true</code> or <code>false</code>) is rejected at compile time with an error message that names the macro. A character of any character type (<code>'a'</code>, <code>L'a'</code>, <code>u8'a'</code>, ...) is rejected, too, although it is an integer.</p> <ul> <li><code>0</code> is allowed, and means that every operation uses its explicit stack from the first level on and no operation recurses over the nesting of a value at all. That needs a constant amount of call stack (at most 16 KiB in the measurements below, for a value nested 20,000 levels deep) and is the setting for tiny stacks, at the price of speed (see <a href=#speed>Speed</a>).</li> <li><code>254</code> is the largest allowed value. Copying a value and comparing two values (with <code>&lt;=&gt;</code>, or with the operators on objects and arrays of a custom type) cannot pass the depth down as an argument, because the signatures of the copy constructor and the operators are fixed. They count the levels they have descended into in a variable of type <code class=highlight><span class=n>std</span><span class=o>::</span><span class=kt>uint8_t</span></code> that exists once per thread (see <a href=../json_no_thread_local/ ><code>JSON_NO_THREAD_LOCAL</code></a>). Only the levels that are descended into are counted, so the count never exceeds the limit, not even when user code (a copy constructor of a custom base class, say) copies a value while a copy is going on. A byte holds <code>255</code> at most, and the limit stays below that, so that the count cannot wrap around. (More levels would hardly be useful: <code>254</code> levels need up to 576 KiB of stack in an unoptimized build already, twice as much as the default.)</li> </ul> </div> <h3 id=stack-needed>Stack needed<a class=headerlink href=#stack-needed title="Permanent link">&para;</a></h3> <p>The tables show the smallest stack that an operation needs, in KiB, at several limits, on a value that is nested more deeply than the limit (limit + 10 levels). Each cell shows the result for Clang (Apple clang 21) and for <abbr title="GNU Compiler Collection">GCC</abbr> 16, separated by a slash; both measured on macOS with arm64, compiling in C++20 mode. The operations run in a thread whose stack has the size given, and are not given any stack that they do not need: the value is built, and the result destroyed, outside of that thread. Stacks can only be set in steps of 16 KiB (the page size), so <code>16</code> means "16 KiB or less". A row stands for all operations listed; the table shows the largest value among them.</p> <p>Unoptimized (<code>-O0</code>):</p> <table> <thead> <tr> <th>Operation</th> <th style="text-align: right;">limit 16</th> <th style="text-align: right;">limit 32</th> <th style="text-align: right;">limit 64</th> <th style="text-align: right;">limit 128</th> <th style="text-align: right;">limit 254</th> </tr> </thead> <tbody> <tr> <td><code>dump()</code> and <code>dump(indent)</code>, <code>operator&lt;&lt;</code></td> <td style="text-align: right;">48 / 32</td> <td style="text-align: right;">80 / 64</td> <td style="text-align: right;">144 / 128</td> <td style="text-align: right;">288 / 256</td> <td style="text-align: right;">576 / 512</td> </tr> <tr> <td>copy construction and assignment</td> <td style="text-align: right;">32 / 16</td> <td style="text-align: right;">48 / 32</td> <td style="text-align: right;">112 / 80</td> <td style="text-align: right;">224 / 144</td> <td style="text-align: right;">432 / 304</td> </tr> <tr> <td><code>==</code></td> <td style="text-align: right;">16 / 16</td> <td style="text-align: right;">16 / 16</td> <td style="text-align: right;">16 / 16</td> <td style="text-align: right;">48 / 32</td> <td style="text-align: right;">96 / 48</td> </tr> <tr> <td><code>&lt;=&gt;</code> (C++20)</td> <td style="text-align: right;">16 / 16</td> <td style="text-align: right;">16 / 16</td> <td style="text-align: right;">32 / 32</td> <td style="text-align: right;">64 / 64</td> <td style="text-align: right;">144 / 128</td> </tr> <tr> <td><code>std::hash</code></td> <td style="text-align: right;">16 / 16</td> <td style="text-align: right;">16 / 16</td> <td style="text-align: right;">32 / 32</td> <td style="text-align: right;">80 / 64</td> <td style="text-align: right;">160 / 128</td> </tr> <tr> <td><code>merge_patch</code>, <code>update(j, true)</code>, <code>patch</code></td> <td style="text-align: right;">32 / 16</td> <td style="text-align: right;">48 / 32</td> <td style="text-align: right;">112 / Line truncated
<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;utility&gt;</span>
<span class=c1>// walk over at most 16 nesting levels on the call stack, and over the rest with an explicit stack</span>
<span class=cp>#define JSON_RECURSION_DEPTH_LIMIT 16</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span>
<span class=k>using</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span>
<span class=kt>int</span><span class=w> </span><span class=nf>main</span><span class=p>()</span>
<span class=p>{</span>
<span class=w> </span><span class=c1>// an array nested 5,000 levels deep, built without recursion</span>
<span class=w> </span><span class=n>json</span><span class=w> </span><span class=n>j</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=mi>1</span><span class=p>;</span>
<span class=w> </span><span class=k>for</span><span class=w> </span><span class=p>(</span><span class=kt>int</span><span class=w> </span><span class=n>i</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=mi>0</span><span class=p>;</span><span class=w> </span><span class=n>i</span><span class=w> </span><span class=o>&lt;</span><span class=w> </span><span class=mi>5000</span><span class=p>;</span><span class=w> </span><span class=o>++</span><span class=n>i</span><span class=p>)</span>
<span class=w> </span><span class=p>{</span>
<span class=w> </span><span class=n>json</span><span class=w> </span><span class=n>outer</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>json</span><span class=o>::</span><span class=n>array</span><span class=p>();</span>
<span class=w> </span><span class=n>outer</span><span class=p>.</span><span class=n>push_back</span><span class=p>(</span><span class=n>std</span><span class=o>::</span><span class=n>move</span><span class=p>(</span><span class=n>j</span><span class=p>));</span>
<span class=w> </span><span class=n>j</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>move</span><span class=p>(</span><span class=n>outer</span><span class=p>);</span>
<span class=w> </span><span class=p>}</span>
<span class=w> </span><span class=c1>// the results are those of any other limit</span>
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=n>copy</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>j</span><span class=p>;</span>
<span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>cout</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>boolalpha</span><span class=p>;</span>
<span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>cout</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=s>"limit: "</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=n>JSON_RECURSION_DEPTH_LIMIT</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=sc>'\n'</span><span class=p>;</span>
<span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>cout</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=s>"copy equals original: "</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=p>(</span><span class=n>copy</span><span class=w> </span><span class=o>==</span><span class=w> </span><span class=n>j</span><span class=p>)</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=sc>'\n'</span><span class=p>;</span>
<span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>cout</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=s>"length of dump(): "</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=n>j</span><span class=p>.</span><span class=n>dump</span><span class=p>().</span><span class=n>size</span><span class=p>()</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=sc>'\n'</span><span class=p>;</span>
<span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>cout</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=s>"same hash: "</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=p>(</span><span class=n>std</span><span class=o>::</span><span class=n>hash</span><span class=o>&lt;</span><span class=n>json</span><span class=o>&gt;</span><span class=w> </span><span class=p>{}(</span><span class=n>copy</span><span class=p>)</span><span class=w> </span><span class=o>==</span><span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>hash</span><span class=o>&lt;</span><span class=n>json</span><span class=o>&gt;</span><span class=w> </span><span class=p>{}(</span><span class=n>j</span><span class=p>))</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=sc>'\n'</span><span class=p>;</span>
<span class=p>}</span>
</code></pre></div> <p>Output:</p> <div class=highlight><pre><span></span><code>limit: 16
copy equals original: true
length of dump(): 10001
same hash: true
</code></pre></div> </details> <details class=example> <summary>Example: find out how much stack an operation needs</summary> <p>The program runs <code>dump()</code> on a value nested <code>depth</code> levels deep in a thread with a stack of <code>kib</code> KiB. Compile it with the options and the limit that you use, e.g. <code>-DJSON_RECURSION_DEPTH_LIMIT=64</code>, run it with <code>depth</code> set to the limit plus 10 and decreasing values of <code>kib</code> (the stack size must be a multiple of the page size, often 4 or 16 KiB), and note the smallest stack with which it still finishes. That is how the tables above were measured.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;cstdlib&gt;</span>
<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;string&gt;</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;utility&gt;</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;pthread.h&gt;</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span>
<span class=k>static</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=w> </span><span class=n>value</span><span class=p>;</span>
<span class=k>static</span><span class=w> </span><span class=kt>void</span><span class=o>*</span><span class=w> </span><span class=nf>run</span><span class=p>(</span><span class=kt>void</span><span class=o>*</span><span class=p>)</span>
<span class=p>{</span>
<span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>cout</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=s>"dump() ok, "</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=n>value</span><span class=p>.</span><span class=n>dump</span><span class=p>().</span><span class=n>size</span><span class=p>()</span><span class=w> </span><span class=o>&lt;&lt;</span><span class=w> </span><span class=s>" bytes</span><span class=se>\n</span><span class=s>"</span><span class=p>;</span>
<span class=w> </span><span class=k>return</span><span class=w> </span><span class=nb>nullptr</span><span class=p>;</span>
<span class=p>}</span>
<span class=kt>int</span><span class=w> </span><span class=nf>main</span><span class=p>(</span><span class=kt>int</span><span class=w> </span><span class=n>argc</span><span class=p>,</span><span class=w> </span><span class=kt>char</span><span class=o>**</span><span class=w> </span><span class=n>argv</span><span class=p>)</span>
<span class=p>{</span>
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=kt>int</span><span class=w> </span><span class=n>depth</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>atoi</span><span class=p>(</span><span class=n>argv</span><span class=p>[</span><span class=mi>1</span><span class=p>]);</span>
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>std</span><span class=o>::</span><span class=kt>size_t</span><span class=w> </span><span class=n>kib</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=k>static_cast</span><span class=o>&lt;</span><span class=n>std</span><span class=o>::</span><span class=kt>size_t</span><span class=o>&gt;</span><span class=p>(</span><span class=n>std</span><span class=o>::</span><span class=n>atoi</span><span class=p>(</span><span class=n>argv</span><span class=p>[</span><span class=mi>2</span><span class=p>]));</span>
<span class=w> </span><span class=c1>// built on the main thread, without recursion</span>
<span class=w> </span><span class=n>value</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=mi>1</span><span class=p>;</span>
<span class=w> </span><span class=k>for</span><span class=w> </span><span class=p>(</span><span class=kt>int</span><span class=w> </span><span class=n>i</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=mi>0</span><span class=p>;</span><span class=w> </span><span class=n>i</span><span class=w> </span><span class=o>&lt;</span><span class=w> </span><span class=n>depth</span><span class=p>;</span><span class=w> </span><span class=o>++</span><span class=n>i</span><span class=p>)</span>
<span class=w> </span><span class=p>{</span>
<span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=w> </span><span class=n>outer</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=o>::</span><span class=n>array</span><span class=p>();</span>
<span class=w> </span><span class=n>outer</span><span class=p>.</span><span class=n>push_back</span><span class=p>(</span><span class=n>std</span><span class=o>::</span><span class=n>move</span><span class=p>(</span><span class=n>value</span><span class=p>));</span>
<span class=w> </span><span class=n>value</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>move</span><span class=p>(</span><span class=n>outer</span><span class=p>);</span>
<span class=w> </span><span class=p>}</span>
<span class=w> </span><span class=n>pthread_attr_t</span><span class=w> </span><span class=n>attr</span><span class=p>;</span>
<span class=w> </span><span class=n>pthread_attr_init</span><span class=p>(</span><span class=o>&amp;</span><span class=n>attr</span><span class=p>);</span>
<span class=w> </span><span class=n>pthread_attr_setstacksize</span><span class=p>(</span><span class=o>&amp;</span><span class=n>attr</span><span class=p>,</span><span class=w> </span><span class=n>kib</span><span class=w> </span><span class=o>*</span><span class=w> </span><span class=mi>1024</span><span class=p>);</span>
<span class=w> </span><span class=n>pthread_t</span><span class=w> </span><span class=kr>thread</span><span class=p>;</span>
<span class=w> </span><span class=n>pthread_create</span><span class=p>(</span><span class=o>&amp;</span><span class=kr>thread</span><span class=p>,</span><span class=w> </span><span class=o>&amp;</span><span class=n>attr</span><span class=p>,</span><span class=w> </span><span class=n>run</span><span class=p>,</span><span class=w> </span><span class=nb>nullptr</span><span class=p>);</span>
<span class=w> </span><span class=n>pthread_join</span><span class=p>(</span><span class=kr>thread</span><span class=p>,</span><span class=w> </span><span class=nb>nullptr</span><span class=p>);</span>
<span class=p>}</span>
</code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../../../features/parsing/untrusted_input/#nesting-depth>Nesting depth</a> - how the library handles deeply nested values</li> <li><a href=../json_no_thread_local/ ><code>JSON_NO_THREAD_LOCAL</code></a> - switch off the use of <code>thread_local</code> storage</li> <li><a href=../../../features/macros/ >Supported Macros</a> - guide to all supported macros</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ul> <li>Added in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>.</li> </ul> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="November 11, 2026 21:32:05 UTC">November 11, 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> <nav class="md-footer__inner md-grid" aria-label=Footer> <a href=../json_precise_stream_position/ class="md-footer__link md-footer__link--prev" aria-label="Previous: JSON_PRECISE_STREAM_POSITION"> <div class="md-footer__button md-icon"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg> </div> <div class=md-footer__title> <span class=md-footer__direction> Previous </span> <div class=md-ellipsis> JSON_PRECISE_STREAM_POSITION </div> </div> </a> <a href=../json_skip_library_version_check/ class="md-footer__link md-footer__link--next" aria-label="Next: JSON_SKIP_LIBRARY_VERSION_CHECK"> <div class=md-footer__title> <span class=md-footer__direction> Next </span> <div class=md-ellipsis> JSON_SKIP_LIBRARY_VERSION_CHECK </div> </div> <div class="md-footer__button md-icon"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11z"/></svg> </div> </a> </nav> <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-Line truncated