This commit is contained in:
nlohmann committed 2026-05-21 20:20:43 +00:00
1 parent 74caa1b78d
commit 0d8a3f1278
247 files changed
+488 -488

No files matched your search

@@ -19,4 +19,4 @@
<span class=w> </span><span class=nt>&quot;age&quot;</span><span class=p>:</span><span class=w> </span><span class=mi>42</span><span class=p>,</span>
<span class=w> </span><span class=nt>&quot;hobbies&quot;</span><span class=p>:</span><span class=w> </span><span class=p>[</span><span class=s2>&quot;running&quot;</span><span class=p>,</span><span class=w> </span><span class=s2>&quot;reading&quot;</span><span class=p>,</span><span class=w> </span><span class=kc>null</span><span class=p>,</span><span class=w> </span><span class=s2>&quot;cooking&quot;</span><span class=p>]</span>
<span class=p>}</span>
</code></pre></div> </details> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition info"> <p class=admonition-title>Design rationale</p> <p>The library behaves differently to <code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>vector</span></code> and <code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>map</span></code>:</p> <ul> <li><code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>vector</span><span class=o>::</span><span class=k>operator</span><span class=p>[]</span></code> never inserts a new element.</li> <li><code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>map</span><span class=o>::</span><span class=k>operator</span><span class=p>[]</span></code> is not available for const values.</li> </ul> <p>The type <code class=highlight><span class=n>json</span></code> wraps all <abbr title="JavaScript Object Notation">JSON</abbr> value types. It would be impossible to remove <a href=../../../api/basic_json/operator%5B%5D/ ><code>operator[]</code></a> for const objects. At the same time, inserting elements for non-const objects is really convenient as it avoids awkward <code>insert</code> calls. To this end, we decided to have an inserting non-const behavior for both arrays and objects.</p> </div> <div class="admonition info"> <p class=admonition-title>Info</p> <p>The access is unchecked. In case the passed object key does not exist or the passed array index is invalid, no exception is thrown.</p> </div> <div class="admonition danger"> <p class=admonition-title>Danger</p> <ul> <li>It is <strong>undefined behavior</strong> to access a const object with a non-existing key.</li> <li>It is <strong>undefined behavior</strong> to access a const array with an invalid index.</li> <li>In debug mode, an <strong>assertion</strong> will fire in both cases. You can disable assertions by defining the preprocessor symbol <code class=highlight><span class=n>NDEBUG</span></code> or redefine the macro <a href=../../macros/#json_assertx><code>JSON_ASSERT(x)</code></a>. See the documentation on <a href=../../assertions/ >runtime assertions</a> for more information.</li> </ul> </div> <div class="admonition failure"> <p class=admonition-title>Exceptions</p> <p><code>operator[]</code> can only be used with objects (with a string argument) or with arrays (with a numeric argument). For other types, a <a href=../../../home/exceptions/#jsonexceptiontype_error305><code>basic_json::type_error</code></a> is thrown.</p> </div> <h2 id=summary>Summary<a class=headerlink href=#summary title="Permanent link">&para;</a></h2> <table> <thead> <tr> <th>scenario</th> <th>non-const value</th> <th>const value</th> </tr> </thead> <tbody> <tr> <td>access to existing object key</td> <td>reference to existing value is returned</td> <td>const reference to existing value is returned</td> </tr> <tr> <td>access to valid array index</td> <td>reference to existing value is returned</td> <td>const reference to existing value is returned</td> </tr> <tr> <td>access to non-existing object key</td> <td>reference to newly inserted <code class=highlight><span class=kc>null</span></code> value is returned</td> <td><strong>undefined behavior</strong>; <a href=../../assertions/ >runtime assertion</a> in debug mode</td> </tr> <tr> <td>access to invalid array index</td> <td>reference to newly inserted <code class=highlight><span class=kc>null</span></code> value is returned; any index between previous maximal index and passed index are filled with <code class=highlight><span class=kc>null</span></code></td> <td><strong>undefined behavior</strong>; <a href=../../assertions/ >runtime assertion</a> in debug mode</td> </tr> </tbody> </table> <!-- 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="May 18, 2026 18:37:07 UTC">May 18, 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(locatLine truncated
</code></pre></div> </details> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition info"> <p class=admonition-title>Design rationale</p> <p>The library behaves differently to <code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>vector</span></code> and <code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>map</span></code>:</p> <ul> <li><code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>vector</span><span class=o>::</span><span class=k>operator</span><span class=p>[]</span></code> never inserts a new element.</li> <li><code class=highlight><span class=n>std</span><span class=o>::</span><span class=n>map</span><span class=o>::</span><span class=k>operator</span><span class=p>[]</span></code> is not available for const values.</li> </ul> <p>The type <code class=highlight><span class=n>json</span></code> wraps all <abbr title="JavaScript Object Notation">JSON</abbr> value types. It would be impossible to remove <a href=../../../api/basic_json/operator%5B%5D/ ><code>operator[]</code></a> for const objects. At the same time, inserting elements for non-const objects is really convenient as it avoids awkward <code>insert</code> calls. To this end, we decided to have an inserting non-const behavior for both arrays and objects.</p> </div> <div class="admonition info"> <p class=admonition-title>Info</p> <p>The access is unchecked. In case the passed object key does not exist or the passed array index is invalid, no exception is thrown.</p> </div> <div class="admonition danger"> <p class=admonition-title>Danger</p> <ul> <li>It is <strong>undefined behavior</strong> to access a const object with a non-existing key.</li> <li>It is <strong>undefined behavior</strong> to access a const array with an invalid index.</li> <li>In debug mode, an <strong>assertion</strong> will fire in both cases. You can disable assertions by defining the preprocessor symbol <code class=highlight><span class=n>NDEBUG</span></code> or redefine the macro <a href=../../macros/#json_assertx><code>JSON_ASSERT(x)</code></a>. See the documentation on <a href=../../assertions/ >runtime assertions</a> for more information.</li> </ul> </div> <div class="admonition failure"> <p class=admonition-title>Exceptions</p> <p><code>operator[]</code> can only be used with objects (with a string argument) or with arrays (with a numeric argument). For other types, a <a href=../../../home/exceptions/#jsonexceptiontype_error305><code>basic_json::type_error</code></a> is thrown.</p> </div> <h2 id=summary>Summary<a class=headerlink href=#summary title="Permanent link">&para;</a></h2> <table> <thead> <tr> <th>scenario</th> <th>non-const value</th> <th>const value</th> </tr> </thead> <tbody> <tr> <td>access to existing object key</td> <td>reference to existing value is returned</td> <td>const reference to existing value is returned</td> </tr> <tr> <td>access to valid array index</td> <td>reference to existing value is returned</td> <td>const reference to existing value is returned</td> </tr> <tr> <td>access to non-existing object key</td> <td>reference to newly inserted <code class=highlight><span class=kc>null</span></code> value is returned</td> <td><strong>undefined behavior</strong>; <a href=../../assertions/ >runtime assertion</a> in debug mode</td> </tr> <tr> <td>access to invalid array index</td> <td>reference to newly inserted <code class=highlight><span class=kc>null</span></code> value is returned; any index between previous maximal index and passed index are filled with <code class=highlight><span class=kc>null</span></code></td> <td><strong>undefined behavior</strong>; <a href=../../assertions/ >runtime assertion</a> in debug mode</td> </tr> </tbody> </table> <!-- 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="May 21, 2026 20:19:34 UTC">May 21, 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(locatLine truncated