</code></pre></div><p>Deserializes a given input to a JSON value using the MessagePack serialization format.</p><ol><li>Reads from a compatible input.</li><li>Reads from an iterator range.</li></ol><p>The exact mapping and its limitations is described on a <ahref=../../../features/binary_formats/messagepack/>dedicated page</a>.</p><h2id=template-parameters>Template parameters<aclass=headerlinkhref=#template-parameterstitle="Permanent link">¶</a></h2><dl><dt><code>InputType</code></dt><dd><p>A compatible input, for instance:</p><ul><li>an <code>std::istream</code> object</li><li>a <code>FILE</code> pointer</li><li>a C-style array of characters</li><li>a pointer to a null-terminated string of single byte characters</li><li>an object <code>obj</code> for which <code>begin(obj)</code> and <code>end(obj)</code> produces a valid pair of iterators.</li></ul></dd><dt><code>IteratorType</code></dt><dd>a compatible iterator type</dd></dl><h2id=parameters>Parameters<aclass=headerlinkhref=#parameterstitle="Permanent link">¶</a></h2><dl><dt><code>i</code> (in)</dt><dd>an input in MessagePack format convertible to an input adapter</dd><dt><code>first</code> (in)</dt><dd>iterator to start of the input</dd><dt><code>last</code> (in)</dt><dd>iterator to end of the input</dd><dt><code>strict</code> (in)</dt><dd>whether to expect the input to be consumed until EOF (<codeclass=highlight><spanclass=nb>true</span><spanclass=w></span></code> by default)</dd><dt><code>allow_exceptions</code> (in)</dt><dd>whether to throw exceptions in case of a parse error (optional, <codeclass=highlight><spanclass=nb>true</span><spanclass=w></span></code> by default)</dd></dl><h2id=return-value>Return value<aclass=headerlinkhref=#return-valuetitle="Permanent link">¶</a></h2><p>deserialized JSON value; in case of a parse error and <code>allow_exceptions</code> set to <codeclass=highlight><spanclass=nb>false</span><spanclass=w></span></code>, the return value will be <code>value_t::discarded</code>. The latter can be checked with <ahref=../is_discarded/><code>is_discarded</code></a>.</p><h2id=exception-safety>Exception safety<aclass=headerlinkhref=#exception-safetytitle="Permanent link">¶</a></h2><p>Strong guarantee: if an exception is thrown, there are no changes in the JSON value.</p><h2id=exceptions>Exceptions<aclass=headerlinkhref=#exceptionstitle="Permanent link">¶</a></h2><ul><li>Throws <ahref=../../../home/exceptions/#jsonexceptionparse_error110>parse_error.110</a> if the given input ends prematurely or the end of file was not reached when <code>strict</code> was set to true</li><li>Throws <ahref=../../../home/exceptions/#jsonexceptionparse_error112>parse_error.112</a> if unsupported features from MessagePack were used in the given input or if the input is not valid MessagePack</li><li>Throws <ahref=../../../home/exceptions/#jsonexceptionparse_error113>parse_error.113</a> if a string was expected as map key, but not found</li></ul><h2id=complexity>Complexity<aclass=headerlinkhref=#complexitytitle="Permanent link">¶</a></h2><p>Linear in the size of the input.</p><h2id=examples>Examples<aclass=headerlinkhref=#examplestitle="Permanent link">¶</a></h2><detailsclass=example><summary>Example</summary><p>The example shows the deserialization of a byte vector in MessagePack format to a JSON value.</p><divclass=highlight><pre><span></span><code><spanclass=cp>#include</span><spanclass=w></span><spanclass=cpf><iostream></span><spanclass=cp></span>
</code></pre></div></details><h2id=version-history>Version history<aclass=headerlinkhref=#version-historytitle="Permanent link">¶</a></h2><ul><li>Added in version 2.0.9.</li><li>Parameter <code>start_index</code> since version 2.1.1.</li><li>Changed to consume input adapters, removed <code>start_index</code> parameter, and added <code>strict</code> parameter in version 3.0.0.</li><li>Added <code>allow_exceptions</code> parameter in version 3.2.0.</li></ul><divclass="admonition warning"><pclass=admonition-title>Deprecation</p><ul><li>Overload (2) replaces calls to <code>from_msgpack</code> with a pointer and a length as first two parameters, which has been deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like <codeclass=highlight><spanclass=n>from_msgpack</span><spanclass=p>(</span><spanclass=n>ptr</span><spanclass=p>,</span><spanclass=w></span><spanclass=n>len</span><spanclass=p>,</span><spanclass=w></span><spanclass=p>...);</span><spanclass=w></span></code> with <codeclass=highlight><spanclass=n>from_msgpack</span><spanclass=p>(</span><spanclass=n>ptr</span><spanclass=p>,</span><spanclass=w></span><spanclass=n>ptr</span><spanclass=o>+</span><spanclass=n>len</span><spanclass=p>,</span><spanclass=w></span><spanclass=p>...);</span><spanclass=w></span></code>.</li><li>Overload (2) replaces calls to <code>from_cbor</code> with a pair of iterators as their first parameter, which has been deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like <codeclass=highlight><spanclass=n>from_msgpack</span><spanclass=p>({</span><spanclass=n>ptr</span><spanclass=p>,</span><spanclass=w></span><spanclass=n>ptr</span><spanclass=o>+</span><spanclass=n>len</span><spanclass=p>},</span><spanclass=w></span><spanclass=p>...);</span><spanclass=w></span></code> with <codeclass=highlight><spanclass=n>from_msgpack</span><spanclass=p>(</span><spanclass=n>ptr</span><spanclass=p>,</span><spanclass=w></span><spanclass=n>ptr</span><spanclass=o>+</span><spanclass=n>len</span><spanclass=p>,</span><spanclass=w></span><spanclass=p>...);</span><spanclass=w></span></code>.</li></ul><p>You should be warned by your compiler with a <code>-Wdeprecated-declarations</code> warning if you are using a deprecated function.</p></div><hr><divclass=md-source-file><small> Last update: <spanclass="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">May 1, 2022</span></small></div></article></div><script>vartabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(varsetofdocument.querySelectorAll(".tabbed-set")){vartab,labels=set.querySelector(".tabbed-labels");for(taboftabs)for(varlabeloflabels.getElementsByTagName("label"))if(label.innerText.trim()===tab){varinput=document.getElementById(label.htmlFor);input.checked=!0;continuee}}</script></div><ahref=#class="md-top md-icon"data-md-component=tophidden><svgxmlns=http://www.w3.org/2000/svgviewbox="0 0 24 24"><pathd="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12Z"/></svg> Back to top </a></main><footerclass=md-footer><navclass="md-footer__inner md-grid"aria-label=Footer><ahref=../from_cbor/class="md-footer__link md-footer__link--prev"aria-label="Previous: from_cbor"rel=prev><divclass="md-footer__button md-icon"><svgxmlns=http://www.w3.org/2000/svgviewbox="0 0 24 24"><pathd="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg></div><divclass=md-footer__title><divclass=md-ellipsis><spanclass=md-footer__direction> Previous </span> from_cbor </div></div></a><ahref=../from_ubjson/class="md-footer__link md-footer__link--next"aria-label="Next: from_ubjson"rel=next><divclass=md-footer__title><divclass=md-ellipsis><spanclass=md-footer__direction> Next </span> from_ubjson </div></div><divclass="md-footer__button md-icon"><svgxmlns=http://www.w3.org/2000/svgviewbox="0 0 24 24"><pathd="M411v2h12l-5.55.51.421.42L19