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></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>
</table>
</dd>
</dl>
<dlclass="exception"><dt>Exceptions</dt><dd>
<tableclass="exception">
<tr><tdclass="paramname">std::domain_error</td><td>if reference token is nonempty and does not begin with a slash (<code>/</code>); example: <code>"JSON pointer must be empty or
begin with /"</code></td></tr>
<tr><tdclass="paramname">std::domain_error</td><td>if a tilde (<code>~</code>) is not followed by <code>0</code> (representing <code>~</code>) or <code>1</code> (representing <code>/</code>); example: <code>"escape error:
~ must be followed with 0 or 1"</code></td></tr>
</table>
</dd>
</dl>
<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> (std::domain_error& e)</div><divclass="line"><aname="l00023"></a><spanclass="lineno"> 23</span>  {</div><divclass="line"><aname="l00024"></a><spanclass="lineno"> 24</span>  std::cout <<<spanclass="stringliteral">"domain_error: "</span><< 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><divclass="line"><aname="l00028"></a><spanclass="lineno"> 28<
</div><!-- fragment --> Output (play with this example <atarget="_blank"href="http://melpon.org/wandbox/permlink/9OR6xQ1rRZDA0W94"><b>online</b></a>): <preclass="fragment">domain_error: JSON pointer must be empty or begin with '/'
domain_error: escape error: '~' must be followed with '0' or '1'
domain_error: escape error: '~' 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>