template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer></div>
<p>Create a JSON pointer according to the syntax described in <ahref="https://tools.ietf.org/html/rfc6901#section-3">Section 3 of RFC6901</a>.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">s</td><td>string representing the JSON pointer; if omitted, the empty string is assumed which references the whole JSON value</td></tr>
<tr><tdclass="paramname">parse_error.107</td><td>if the given JSON pointer <em>s</em> is nonempty and does not begin with a slash (<code>/</code>); see example below</td></tr>
<tr><tdclass="paramname">parse_error.108</td><td>if a tilde (<code>~</code>) in the given JSON pointer <em>s</em> is not followed by <code>0</code> (representing <code>~</code>) or <code>1</code> (representing <code>/</code>); see example below</td></tr>
<dlclass="section user"><dt>Example</dt><dd>The example shows the construction several valid JSON pointers as well as the exceptional behavior. <divclass="fragment"><divclass="line"><aname="l00001"></a><spanclass="lineno"> 1</span> <spanclass="preprocessor">#include "json.hpp"</span></div><divclass="line"><aname="l00002"></a><spanclass="lineno"> 2</span> </div><divclass="line"><aname="l00003"></a><spanclass="lineno"> 3</span> <spanclass="keyword">using</span><aclass="code"href="namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html#a2bfd99e845a2e5cd90aeaf1b1431f474">json</a> = <aclass="code"href="namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html#a2bfd99e845a2e5cd90aeaf1b1431f474">nlohmann::json</a>;</div><divclass="line"><aname="l00004"></a><spanclass="lineno"> 4</span> </div><divclass="line"><aname="l00005"></a><spanclass="lineno"> 5</span> <spanclass="keywordtype">int</span> main()</div><divclass="line"><aname="l00006"></a><spanclass="lineno"> 6</span> {</div><divclass="line"><aname="l00007"></a><spanclass="lineno"> 7</span> <spanclass="comment">// correct JSON pointers</span></div><divclass="line"><aname="l00008"></a><spanclass="lineno"> 8</span>  json::json_pointer p1;</div><divclass="line"><aname="l00009"></a><spanclass="lineno"> 9</span>  json::json_pointer p2(<spanclass="stringliteral">""</span>);</div><divclass="line"><aname="l00010"></a><spanclass="lineno"> 10</span>  json::json_pointer p3(<spanclass="stringliteral">"/"</span>);</div><divclass="line"><aname="l00011"></a><spanclass="lineno"> 11</span>  json::json_pointer p4(<spanclass="stringliteral">"//"</span>);</div><divclass="line"><aname="l00012"></a><spanclass="lineno"> 12</span>  json::json_pointer p5(<spanclass="stringliteral">"/foo/bar"</span>);</div><divclass="line"><aname="l00013"></a><spanclass="lineno"> 13</span>  json::json_pointer p6(<spanclass="stringliteral">"/foo/bar/-"</span>);</div><divclass="line"><aname="l00014"></a><spanclass="lineno"> 14</span>  json::json_pointer p7(<spanclass="stringliteral">"/foo/~0"</span>);</div><divclass="line"><aname="l00015"></a><spanclass="lineno"> 15</span>  json::json_pointer p8(<spanclass="stringliteral">"/foo/~1"</span>);</div><divclass="line"><aname="l00016"></a><spanclass="lineno"> 16</span> </div><divclass="line"><aname="l00017"></a><spanclass="lineno"> 17</span> <spanclass="comment">// error: JSON pointer does not begin with a slash</span></div><divclass="line"><aname="l00018"></a><spanclass="lineno"> 18</span> <spanclass="keywordflow">try</span></div><divclass="line"><aname="l00019"></a><spanclass="lineno"> 19</span>  {</div><divclass="line"><aname="l00020"></a><spanclass="lineno"> 20</span>  json::json_pointer p9(<spanclass="stringliteral">"foo"</span>);</div><divclass="line"><aname="l00021"></a><spanclass="lineno"> 21</span>  }</div><divclass="line"><aname="l00022"></a><spanclass="lineno"> 22</span> <spanclass="keywordflow">catch</span> (<aclass="code"href="classnlohmann_1_1basic__json_af1efc2468e6022be6e35fc2944cabe4d.html#af1efc2468e6022be6e35fc2944cabe4d">json::parse_error</a>& e)</div><divclass="line"><aname="l00023"></a><spanclass="lineno"> 23</span>  {</div><divclass="line"><aname="l00024"></a><spanclass="lineno"> 24</span>  std::cout << e.what() <<<spanclass="charliteral">'\n'</span>;</div><divclass="line"><aname="l00025"></a><spanclass="lineno"> 25</span>  }</div><divclass="line"><aname="l00026"></a><spanclass="lineno"> 26</span> </div><divclass="line"><aname="l00027"></a><spanclass="lineno"> 27</span> <spanclass="comment">// error: JSON pointer uses escape symbol ~ not followed by 0 or 1</span></div><div
<divclass="ttc"id="classnlohmann_1_1basic__json_af1efc2468e6022be6e35fc2944cabe4d_html_af1efc2468e6022be6e35fc2944cabe4d"><divclass="ttname"><ahref="classnlohmann_1_1basic__json_af1efc2468e6022be6e35fc2944cabe4d.html#af1efc2468e6022be6e35fc2944cabe4d">nlohmann::basic_json::parse_error</a></div><divclass="ttdeci">detail::parse_error parse_error</div><divclass="ttdoc">exception indicating a parse error </div><divclass="ttdef"><b>Definition:</b><ahref="json_8hpp_source.html#l01318">json.hpp:1318</a></div></div>
</div><!-- fragment --> Output (play with this example <atarget="_blank"href="https://wandbox.org/permlink/JdZq6bQWjrHew4Dy"><b>online</b></a>): <preclass="fragment">[json.exception.parse_error.107] parse error at 1: JSON pointer must be empty or begin with '/' - was: 'foo'
[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'
[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'
</pre> The example code above can be translated with<preclass="fragment">g++ -std=c++11 -Isrc doc/examples/json_pointer.cpp -o json_pointer </pre></dd></dl>
<pclass="definition">Definition at line <aclass="el"href="json_8hpp_source.html#l12577">12577</a> of file <aclass="el"href="json_8hpp_source.html">json.hpp</a>.</p>