<!DOCTYPE html>
<html>
<head>
<title>json</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
/* GitHub stylesheet for MarkdownPad (http://markdownpad.com) */
/* Author: Nicolas Hery - http://nicolashery.com */
/* Version: b13fe65ca28d2e568c6ed5d7f06581183df8f2ff */
/* Source: https://github.com/nicolahery/markdownpad-github */

/* RESET
=============================================================================*/

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
}

/* BODY
=============================================================================*/

body {
  font-family: Helvetica, arial, freesans, clean, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: #333;
  background-color: #fff;
  padding: 20px;
  max-width: 960px;
  margin: 0 auto;
}

body>*:first-child {
  margin-top: 0 !important;
}

body>*:last-child {
  margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
  margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
  margin: 20px 0 10px;
  padding: 0;
  font-weight: bold;
  -webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
  font-size: inherit;
}

h1 {
  font-size: 28px;
  color: #000;
}

h2 {
  font-size: 24px;
  border-bottom: 1px solid #ccc;
  color: #000;
}

h3 {
  font-size: 18px;
}

h4 {
  font-size: 16px;
}

h5 {
  font-size: 14px;
}

h6 {
  color: #777;
  font-size: 14px;
}

body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
  margin-top: 0;
  padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
  margin-top: 0;
  padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
  margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
  color: #4183C4;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
  padding-left: 30px;
}

ul li > :first-child, 
ol li > :first-child, 
ul li ul:first-of-type, 
ol li ol:first-of-type, 
ul li ol:first-of-type, 
ol li ul:first-of-type {
  margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
  margin-bottom: 0;
}

dl {
  padding: 0;
}

dl dt {
  font-size: 14px;
  font-weight: bold;
  font-style: italic;
  padding: 0;
  margin: 15px 0 5px;
}

dl dt:first-child {
  padding: 0;
}

dl dt>:first-child {
  margin-top: 0px;
}

dl dt>:last-child {
  margin-bottom: 0px;
}

dl dd {
  margin: 0 0 15px;
  padding: 0 15px;
}

dl dd>:first-child {
  margin-top: 0px;
}

dl dd>:last-child {
  margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
  font-size: 12px;
  font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
  margin: 0 0px;
  padding: 0px 0px;
  white-space: nowrap;
  border: 1px solid #eaeaea;
  background-color: #f8f8f8;
  border-radius: 3px;
}

pre>code {
  margin: 0;
  padding: 0;
  white-space: pre;
  border: none;
  background: transparent;
}

pre {
  background-color: #f8f8f8;
  border: 1px solid #ccc;
  font-size: 13px;
  line-height: 19px;
  overflow: auto;
  padding: 6px 10px;
  border-radius: 3px;
}

pre code, pre tt {
  background-color: transparent;
  border: none;
}

kbd {
    -moz-border-bottom-colors: none;
    -moz-border-left-colors: none;
    -moz-border-right-colors: none;
    -moz-border-top-colors: none;
    background-color: #DDDDDD;
    background-image: linear-gradient(#F1F1F1, #DDDDDD);
    background-repeat: repeat-x;
    border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
    border-image: none;
    border-radius: 2px 2px 2px 2px;
    border-style: solid;
    border-width: 1px;
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    line-height: 10px;
    padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
  border-left: 4px solid #DDD;
  padding: 0 15px;
  color: #777;
}

blockquote>:first-child {
  margin-top: 0px;
}

blockquote>:last-child {
  margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
  clear: both;
  margin: 15px 0;
  height: 0px;
  overflow: hidden;
  border: none;
  background: transparent;
  border-bottom: 4px solid #ddd;
  padding: 0;
}

/* TABLES
=============================================================================*/

table th {
  font-weight: bold;
}

table th, table td {
  border: 1px solid #ccc;
  padding: 6px 13px;
}

table tr {
  border-top: 1px solid #ccc;
  background-color: #fff;
}

table tr:nth-child(2n) {
  background-color: #f8f8f8;
}

/* IMAGES
=============================================================================*/

img {
  max-width: 100%
}
</style>
<style type="text/css">
.highlight  { background: #ffffff; }
.highlight .c { color: #999988; font-style: italic } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { font-weight: bold } /* Keyword */
.highlight .o { font-weight: bold } /* Operator */
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #999999 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #aaaaaa } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { font-weight: bold } /* Keyword.Constant */
.highlight .kd { font-weight: bold } /* Keyword.Declaration */
.highlight .kp { font-weight: bold } /* Keyword.Pseudo */
.highlight .kr { font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #009999 } /* Literal.Number */
.highlight .s { color: #d14 } /* Literal.String */
.highlight .na { color: #008080 } /* Name.Attribute */
.highlight .nb { color: #0086B3 } /* Name.Builtin */
.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
.highlight .no { color: #008080 } /* Name.Constant */
.highlight .ni { color: #800080 } /* Name.Entity */
.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
.highlight .nn { color: #555555 } /* Name.Namespace */
.highlight .nt { color: #000080 } /* Name.Tag */
.highlight .nv { color: #008080 } /* Name.Variable */
.highlight .ow { font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #009999 } /* Literal.Number.Float */
.highlight .mh { color: #009999 } /* Literal.Number.Hex */
.highlight .mi { color: #009999 } /* Literal.Number.Integer */
.highlight .mo { color: #009999 } /* Literal.Number.Oct */
.highlight .sb { color: #d14 } /* Literal.String.Backtick */
.highlight .sc { color: #d14 } /* Literal.String.Char */
.highlight .sd { color: #d14 } /* Literal.String.Doc */
.highlight .s2 { color: #d14 } /* Literal.String.Double */
.highlight .se { color: #d14 } /* Literal.String.Escape */
.highlight .sh { color: #d14 } /* Literal.String.Heredoc */
.highlight .si { color: #d14 } /* Literal.String.Interpol */
.highlight .sx { color: #d14 } /* Literal.String.Other */
.highlight .sr { color: #009926 } /* Literal.String.Regex */
.highlight .s1 { color: #d14 } /* Literal.String.Single */
.highlight .ss { color: #990073 } /* Literal.String.Symbol */
.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #008080 } /* Name.Variable.Class */
.highlight .vg { color: #008080 } /* Name.Variable.Global */
.highlight .vi { color: #008080 } /* Name.Variable.Instance */
.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
.pl-c {
    color: #969896;
}

.pl-c1,.pl-mdh,.pl-mm,.pl-mp,.pl-mr,.pl-s1 .pl-v,.pl-s3,.pl-sc,.pl-sv {
    color: #0086b3;
}

.pl-e,.pl-en {
    color: #795da3;
}

.pl-s1 .pl-s2,.pl-smi,.pl-smp,.pl-stj,.pl-vo,.pl-vpf {
    color: #333;
}

.pl-ent {
    color: #63a35c;
}

.pl-k,.pl-s,.pl-st {
    color: #a71d5d;
}

.pl-pds,.pl-s1,.pl-s1 .pl-pse .pl-s2,.pl-sr,.pl-sr .pl-cce,.pl-sr .pl-sra,.pl-sr .pl-sre,.pl-src,.pl-v {
    color: #df5000;
}

.pl-id {
    color: #b52a1d;
}

.pl-ii {
    background-color: #b52a1d;
    color: #f8f8f8;
}

.pl-sr .pl-cce {
    color: #63a35c;
    font-weight: bold;
}

.pl-ml {
    color: #693a17;
}

.pl-mh,.pl-mh .pl-en,.pl-ms {
    color: #1d3e81;
    font-weight: bold;
}

.pl-mq {
    color: #008080;
}

.pl-mi {
    color: #333;
    font-style: italic;
}

.pl-mb {
    color: #333;
    font-weight: bold;
}

.pl-md,.pl-mdhf {
    background-color: #ffecec;
    color: #bd2c00;
}

.pl-mdht,.pl-mi1 {
    background-color: #eaffea;
    color: #55a532;
}

.pl-mdr {
    color: #795da3;
    font-weight: bold;
}

.pl-mo {
    color: #1d3e81;
}
.task-list {
padding-left:10px;
margin-bottom:0;
}

.task-list li {
    margin-left: 20px;
}

.task-list-item {
list-style-type:none;
padding-left:10px;
}

.task-list-item label {
font-weight:400;
}

.task-list-item.enabled label {
cursor:pointer;
}

.task-list-item+.task-list-item {
margin-top:3px;
}

.task-list-item-checkbox {
display:inline-block;
margin-left:-20px;
margin-right:3px;
vertical-align:1px;
}
</style>
</head>
<body>
<div class="highlight highlight-source-c++"><pre>    jsoncons::json

    <span class="pl-k">typedef</span> basic_json&lt;<span class="pl-k">char</span>,std::allocator&lt;<span class="pl-k">char</span>&gt;&gt; json</pre></div>

<p>The <code>json</code> class is an instantiation of the <code>basic_json</code> class template that uses <code>char</code> as the character type. The <code>jsoncons</code> library will always rebind the given allocator from the template parameter to internal data structures.</p>

<h3>Header</h3>

<pre><code>#include "jsoncons/json.hpp"
</code></pre>

<h3>Member types</h3>

<table>
<thead>
<tr>
<th>Member type</th>
<th>Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>allocator_type</code></td>
<td>Allocator type</td>
</tr>
<tr>
<td><code>string_allocator</code></td>
<td>String allocator type</td>
</tr>
<tr>
<td><code>array_allocator</code></td>
<td>Array allocator type</td>
</tr>
<tr>
<td><code>object_allocator</code></td>
<td>Object allocator type</td>
</tr>
<tr>
<td><code>string_type</code></td>
<td>Default <code>string_type</code> is <code>std::string</code>
</td>
</tr>
<tr>
<td><code>member_type</code></td>
<td>
<a href="json_member_type">member_type</a> is a class that stores a name and a json value</td>
</tr>
<tr>
<td><code>any</code></td>
<td>
<a href="json%20any">any</a> can contain any value that supports copy construction and assignment.</td>
</tr>
<tr>
<td><code>null_type</code></td>
<td>An alias for <code>jsoncons::null_type</code>
</td>
</tr>
<tr>
<td><code>object</code></td>
<td>json object type</td>
</tr>
<tr>
<td><code>array</code></td>
<td>json array type</td>
</tr>
<tr>
<td><code>object_iterator</code></td>
<td>A bidirectional iterator to <code>json::member_type</code>
</td>
</tr>
<tr>
<td><code>const_object_iterator</code></td>
<td>A bidirectional iterator to <code>const json::member_type</code>
</td>
</tr>
<tr>
<td><code>array_iterator</code></td>
<td>A random access iterator to <code>json</code>
</td>
</tr>
<tr>
<td><code>const_array_iterator</code></td>
<td>A random access iterator to <code>const json</code>
</td>
</tr>
<tr>
<td><code>object_range</code></td>
<td>An <code>object_range</code> provides a pair of bidirectional iterators, defined by <code>begin()</code> and <code>end()</code>, for accessing the members of a json object. An <code>object_range</code> supports range-based for loops over the members.</td>
</tr>
<tr>
<td><code>const_object_range</code></td>
<td>A <code>const_object_range</code> provides a pair of const bidirectional iterators, defined by <code>begin()</code> and <code>end()</code>, for accessing the members of a json object.</td>
</tr>
<tr>
<td><code>array_range</code></td>
<td>An <code>array_range</code> provides a pair of random access iterators, defined by <code>begin()</code> and <code>end()</code>, for accessing the elements of a json array. An <code>array_range</code> supports range-based for loops over the elements.</td>
</tr>
<tr>
<td><code>const_array_range</code></td>
<td>A <code>const_array_range</code> provides a pair of const random access iterators, defined by <code>begin()</code> and <code>end()</code>, for accessing the elements of a json array.</td>
</tr>
</tbody>
</table>

<h3>Static member functions</h3>

<pre><code>static json parse(const string_type&amp; s)
static json parse(const string_type&amp; s, 
                  parse_error_handler&amp; err_handler)
</code></pre>

<p>Parses a string of JSON text and returns a json object or array value. <br>
Throws <a href="parse_exception">parse_exception</a> if parsing fails.</p>

<pre><code>static json parse_stream(std::istream&amp; is)
static json parse_stream(std::istream&amp; is, 
                         parse_error_handler&amp; err_handler)
</code></pre>

<p>Parses an input stream of JSON text and returns a json object or array value. <br>
Throws <a href="parse_exception">parse_exception</a> if parsing fails.</p>

<pre><code>static json parse_file(const std::string&amp; filename)
static json parse_file(const std::string&amp; filename, 
                       parse_error_handler&amp; err_handler)
</code></pre>

<p>Opens a binary input stream to a JSON unicode file, parsing the file assuming UTF-8, and returns a json object or array value. This method expects that the file contains UTF-8 (or clean 7 bit ASCII), if that is not the case, use the <code>parse</code> method that takes an <code>std::istream</code> instead, imbue your stream with the appropriate facet for handling unicode conversions.<br>
Throws <a href="parse_exception">parse_exception</a> if parsing fails.</p>

<pre><code>static json make_array()

static json make_array(size_t n, const array_allocator&amp; allocator = array_allocator())

template &lt;typename T&gt;
static json make_array(size_ n, const T&amp; val)

template &lt;typename T&gt;
static json make_array(size_ n, const T&amp; val, const array_allocator&amp; allocator = array_allocator())

template &lt;size_t N&gt;
static json make_array(size_t size1 ... size_t sizeN)

template &lt;size_t N,typename T&gt;
static json make_array(size_t size1 ... size_t sizeN, const T&amp; val)

template &lt;size_t N,typename T&gt;
static json make_array(size_t size1 ... size_t sizeN, const T&amp; val, const array_allocator&amp; allocator)
</code></pre>

<p>Makes a multidimensional array with the number of dimensions specified as a template parameter. The size of each dimension is passed as a parameter, and optionally an inital value. If no initial value, the default is an empty json object. The elements may be accessed using familiar C++ native array syntax.</p>

<h3>Constructors</h3>

<pre><code>json()
</code></pre>

<p>Constructs an empty json object. </p>

<pre><code>json(const allocator_type&amp; allocator)
</code></pre>

<p>Constructs a json object. </p>

<pre><code>json(std::initializer_list&lt;json&gt; list, const allocator_type&amp; allocator)
</code></pre>

<p>Constructs a json array with the elements of the initializer list <code>init</code>. </p>

<pre><code>json(const json&amp; val)
</code></pre>

<p>Constructs a copy of val</p>

<pre><code>json(const json&amp; val, const allocator_type&amp; allocator)
</code></pre>

<p>Copy with allocator</p>

<pre><code>json(json&amp;&amp; val)
</code></pre>

<p>Acquires the contents of val, leaving val a <code>null</code> value</p>

<pre><code>json(json&amp;&amp; val, const allocator_type&amp; allocator)
</code></pre>

<p>Move with allocator</p>

<pre><code>template &lt;typename T&gt;
json(T val, const allocator_type&amp; allocator=allocator_type())
</code></pre>

<p>Constructs a <code>json</code> value for types supported in <code>json_type_traits</code></p>

<pre><code>template &lt;class InputIterator&gt;
json(InputIterator first, InputIterator last, 
     const allocator_type&amp; allocator=allocator_type())
</code></pre>

<p>Constructs a json array with the elements in the range [first,last).</p>

<h3>Destructor</h3>

<pre><code>~json()
</code></pre>

<p>Destroys all values and deletes all memory allocated for strings, arrays, and objects.</p>

<h3>Assignment operator</h3>

<pre><code>json&amp; operator=(const json&amp; rhs)
json&amp; operator=(json&amp;&amp; rhs)

template &lt;class T&gt;
json&amp; operator=(T rhs)
</code></pre>

<p>Assigns a new value to a <code>json</code> variable, replacing it's current contents.</p>

<h3>Ranges and Iterators</h3>

<pre><code>object_range members();  
const_object_range members() const;  
</code></pre>

<p>Returns a "range" defined by <code>begin()</code> and <code>end()</code> over the members of a <code>json</code> object<br><br>
Throws <code>std::runtime_error</code> if not an object.</p>

<pre><code>array_range elements();
const_array_range elements() const;
</code></pre>

<p>Returns a "range" defined by <code>begin()</code> and <code>end()</code> over the elements of a <code>json</code> array<br><br>
Throws <code>std::runtime_error</code> if not an array.</p>

<h3>Capacity</h3>

<pre><code>size_t size() const noexcept
</code></pre>

<p>Returns the number of elements in a json array, or the number of members in a json object, or <code>zero</code></p>

<pre><code>bool empty() const noexcept
</code></pre>

<p>Returns <code>true</code> if a json string, object or array has no elements, otherwise <code>false</code>.</p>

<pre><code>size_t capacity() const
</code></pre>

<p>Returns the size of the storage space currently allocated for a json object or array.</p>

<pre><code>void reserve(size_t n)
</code></pre>

<p>Increases the capacity of a json object or array to allow at least <code>n</code> members or elements. </p>

<pre><code>void resize(size_t n)
</code></pre>

<p>Resizes a json array so that it contains <code>n</code> elements. </p>

<pre><code>void resize(size_t n, const json&amp; val)
</code></pre>

<p>Resizes a json array so that it contains <code>n</code> elements that are initialized to <code>val</code>. </p>

<h3>Accessors</h3>

<pre><code>size_t count(const string_type&amp; name) const
</code></pre>

<p>Returns the number of object members that match <code>name</code>.    </p>

<pre><code>template &lt;typename T&gt;
bool is() const noexcept
</code></pre>

<p>Returns <code>true</code> if json value has type <code>T</code>, <code>false</code> otherwise.  </p>

<pre><code>bool is&lt;char&gt; const noexcept 
bool is&lt;signed char&gt; const noexcept
bool is&lt;unsigned char&gt; const noexcept
bool is&lt;wchar_t&gt; const noexcept
bool is&lt;short&gt; const noexcept
bool is&lt;unsigned short&gt; const noexcept 
bool is&lt;int&gt; const noexcept 
bool is&lt;unsigned int&gt; const noexcept 
bool is&lt;long&gt; const noexcept 
bool is&lt;unsigned long&gt; const noexcept 
bool is&lt;long long&gt; const noexcept 
bool is&lt;unsigned long long&gt; const noexcept 
</code></pre>

<p>Return <code>true</code> if json value is of integral type and within the range of the template type, <code>false</code> otherwise.  </p>

<pre><code>is&lt;double&gt; 
</code></pre>

<p>Return true if the json value is of floating point type and within the range of the template type, <code>false</code> otherwise.  </p>

<pre><code>is&lt;string_type&gt; 
</code></pre>

<p>Returns <code>true</code> if the json value is of string type, <code>false</code> otherwise.  </p>

<pre><code>is&lt;bool&gt;
</code></pre>

<p>Returns <code>true</code> if the json value is of boolean type, <code>false</code> otherwise.  </p>

<pre><code>is&lt;json::null_type&gt;
</code></pre>

<p>Returns <code>true</code> if the json value is null, <code>false</code> otherwise.  </p>

<pre><code>is&lt;json::any&gt;
</code></pre>

<p>Returns <code>true</code> if the json value is type any, <code>false</code> otherwise.</p>

<pre><code>is&lt;json::object&gt; 
</code></pre>

<p>Returns <code>true</code> if the json value is an object, <code>false</code> otherwise.  </p>

<pre><code>is&lt;json::array&gt; 
</code></pre>

<p>Returns <code>true</code> if the json value is an array, <code>false</code> otherwise.  </p>

<pre><code>is&lt;json::std::vector&lt;T&gt;&gt;
</code></pre>

<p>Returns <code>true</code> if the json value is an array and each element has type <code>T</code>, <code>false</code> otherwise.</p>

<pre><code>bool is_null() const noexcept
bool is_string() const noexcept
bool is_number() const noexcept
bool is_integer() const noexcept
bool is_uinteger() const noexcept
bool is_double() const noexcept
bool is_bool() const noexcept
bool is_object() const noexcept
bool is_array() const noexcept
bool is_any() const noexcept
</code></pre>

<p>Non-generic versions of <code>is_</code> methods</p>

<pre><code>json&amp; operator[](size_t i)
const json&amp; operator[](size_t i) const
</code></pre>

<p>Returns a reference to the value at position i in a json object or array.<br>
Throws <code>std::runtime_error</code> if not an object.</p>

<pre><code>json&amp; operator[](const string_type&amp; name)
</code></pre>

<p>Returns a proxy to a keyed value. If written to, inserts or updates with the new value. If read, evaluates to a reference to the keyed value, if it exists, otherwise throws. <br>
Throws <code>std::runtime_error</code> if not an object.<br>
If read, throws <code>std::out_of_range</code> if the object does not have a member with the specified name.  </p>

<pre><code>const json&amp; operator[](const string_type&amp; name) const
</code></pre>

<p>If <code>name</code> matches the name of a member in the json object, returns a reference to the json object, otherwise throws.<br>
Throws <code>std::runtime_error</code> if not an object.<br>
Throws <code>std::out_of_range</code> if the object does not have a member with the specified name.  </p>

<pre><code>object_iterator find(const string_type&amp; name)
object_iterator find(const char* name)
const_object_iterator find(const string_type&amp; name) const
const_object_iterator find(const char* name) const
</code></pre>

<p>Returns an object iterator to a member whose name compares equal to <code>name</code>. If there is no such member, returns <code>end_member()</code>.<br>
Throws <code>std::runtime_error</code> if not an object.</p>

<pre><code>json&amp; at(const string_type&amp; name)
const json&amp; at(const string_type&amp; name) const
</code></pre>

<p>Returns a reference to the value with the specifed name in a json object.<br>
Throws <code>std::runtime_error</code> if not an object.<br>
Throws <code>std::out_of_range</code> if the object does not have a member with the specified name.  </p>

<pre><code>json&amp; at(size_t i)
const json&amp; at(size_t i) const
</code></pre>

<p>Returns a reference to the element at index <code>i</code> in a json array.<br><br>
Throws <code>std::runtime_error</code> if not an array.<br>
Throws <code>std::out_of_range</code> if the index is outside the bounds of the array.  </p>

<pre><code>template &lt;typename T&gt;
const json get(const string_type&amp; name, T&amp;&amp; default_val) const
</code></pre>

<p>If <code>name</code> matches the name of a member in the json object, returns a copy of the json object, otherwise returns a copy of <code>default_val</code>.<br>
Throws <code>std::runtime_error</code> if not an object.</p>

<pre><code>template &lt;typename T&gt;
T as() const
</code></pre>

<p>Attempts to coerce the json value to the template type</p>

<pre><code>as&lt;bool&gt;
</code></pre>

<p>Returns <code>false</code> if value is <code>false</code> or <code>null</code>, if value is a zero length string, or if value is a zero length array or object. Everything else returns <code>true</code>.</p>

<pre><code>as&lt;double&gt;
</code></pre>

<p>If value is double, returns value, if value is signed or unsigned integer, casts to double, if value is <code>null</code>, returns <code>NaN</code>, otherwise throws.</p>

<pre><code>char as&lt;char&gt; const
signed char as&lt;signed char&gt; const
unsigned char as&lt;unsigned char&gt; const
wchar_t as&lt;wchar_t&gt; const
short as&lt;short&gt; const
unsigned short as&lt;unsigned short&gt; const 
int as&lt;int&gt; const 
unsigned int as&lt;unsigned int&gt; const 
long as&lt;long&gt; const 
unsigned long as&lt;unsigned long&gt; const 
long long as&lt;long long&gt; const 
unsigned long long as&lt;unsigned long long&gt; const 
</code></pre>

<p>Return integer value if value has integral type, performs cast if value has double type, returns 1 or 0 if value has bool type, otherwise throws.</p>

<pre><code>string_type as&lt;string_type&gt;() const noexcept
string_type as&lt;string_type&gt;(const string_allocator&amp; allocator) const noexcept
</code></pre>

<p>If value is string, returns value, otherwise returns result of <code>to_string</code>.</p>

<pre><code>bool as_bool() const noexcept
int64_t as_integer() const
uint64_t as_uinteger() const
double as_double() const
string_type as_string() const noexcept
string_type as_string(const string_allocator&amp; allocator) const noexcept
unsigned int as&lt;unsigned int&gt; const 
</code></pre>

<p>Non-generic versions of <code>as</code> methods</p>

<pre><code>template &lt;typename T&gt;
const T&amp; any_cast() const

template &lt;typename T&gt;
T&amp; any_cast() 
</code></pre>

<p>If the value does not have type <code>any</code>, throws, otherwise casts the value back to the original type.</p>

<h3>Modifiers</h3>

<pre><code>void clear()
</code></pre>

<p>Remove all elements from an array or object value, otherwise do nothing</p>

<pre><code>void erase(array_iterator first, array_iterator last)
</code></pre>

<p>Remove the elements from an array in the range '[first,last)'.<br>
Throws <code>std::runtime_error</code> if not an object.</p>

<pre><code>void erase(object_iterator first, object_iterator last)
</code></pre>

<p>Remove the members from an object in the range '[first,last)'.<br>
Throws <code>std::runtime_error</code> if not an object.</p>

<pre><code>void erase(const string_type&amp; name)
</code></pre>

<p>Remove a member with the specified name from an object<br>
Throws <code>std::runtime_error</code> if not an object.</p>

<pre><code>void shrink_to_fit()
</code></pre>

<p>Requests the removal of unused capacity.</p>

<pre><code>void set(const string_type&amp; name, const json&amp; val)
void set(string_type&amp;&amp; name, const json&amp; val)
void set(const string_type&amp; name, json&amp;&amp; val)
void set(string_type&amp;&amp; name, json&amp;&amp; val)
</code></pre>

<p>Inserts a new member or replaces an existing member in a json object.<br>
Throws <code>std::runtime_error</code> if not an object.</p>

<pre><code>object_iterator set(object_iterator hint, const string_type&amp; name, const json&amp; val)
object_iterator set(object_iterator hint, string_type&amp;&amp; name, const json&amp; val)
object_iterator set(object_iterator hint, const string_type&amp; name, json&amp;&amp; val)
object_iterator set(object_iterator hint, string_type&amp;&amp; name, json&amp;&amp; val)
</code></pre>

<p>Inserts a new member or replaces an existing member in a json object.<br>
Insertion time is optimized if <code>hint</code> points to the member that will precede the inserted member.<br>
Returns a <code>member_terator</code> pointing at the member that was inserted or updated<br>
Throws <code>std::runtime_error</code> if not an object.</p>

<pre><code>void add(const json&amp; val)
void add(json&amp;&amp; val)
</code></pre>

<p>Adds a new element at the end of a json array. The content of <code>val</code> is copied (or moved) to the new element.<br>
Throws <code>std::runtime_error</code> if not an array.</p>

<pre><code>array_iterator add(const_array_iterator pos, const json&amp; val)
array_iterator add(const_array_iterator pos, json&amp;&amp; val)
</code></pre>

<p>Adds a new element at the specified position of a json array, shifting all elements currently at or above that position to the right.<br>
The content of <code>val</code> is copied (or moved) to the new element.<br>
Returns an <code>array_iterator</code> that points to the new value<br>
Throws <code>std::runtime_error</code> if not an array.</p>

<pre><code>void swap(json&amp; val)
</code></pre>

<p>Exchanges the content of the <code>json</code> value with the content of <code>val</code>, which is another <code>json</code> value.</p>

<h3>Relational operators</h3>

<pre><code>bool operator==(const json&amp; rhs) const
</code></pre>

<p>Returns <code>true</code> if two json objects compare equal, <code>false</code> otherwise.</p>

<pre><code>bool operator!=(const json&amp; rhs) const
</code></pre>

<p>Returns <code>true</code> if two json objects do not compare equal, <code>false</code> otherwise.</p>

<h3>Serialization</h3>

<pre><code>string_type to_string(const string_allocator&amp; allocator = string_allocator()) const noexcept
</code></pre>

<p>Inserts json value into string.</p>

<pre><code>string_type to_string(const output_format&amp; format, const string_allocator&amp; allocator = string_allocator()) const
</code></pre>

<p>Inserts json value into string using specified <a href="output_format">output_format</a>.</p>

<pre><code>std::ostream&amp; to_stream(std::ostream&amp; os) const
</code></pre>

<p>Inserts json value into stream with default output format.</p>

<pre><code>std::ostream&amp; to_stream(std::ostream&lt;CharT&gt; os, const output_format&amp; format) const
</code></pre>

<p>Inserts json value into stream using specified <a href="output_format">output_format</a>.</p>

<pre><code>void to_stream(json_output_handler&amp; handler) const
</code></pre>

<p>Reports JSON related events for JSON objects, arrays, object members and array elements to a <a href="json_output_handler">json_output_handler</a>, such as a <a href="json_serializer">json_serializer</a>.</p>

<h3>Non member functions</h3>

<pre><code>std::istream&amp; operator&gt;&gt; (std::istream&amp; os, json&amp; val)
</code></pre>

<p>Reads a <code>json</code> value from a stream.</p>

<pre><code>std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const json&amp; val)
</code></pre>

<p>Inserts json value into stream.</p>

<pre><code>std::ostream&amp; print(const json&amp; val)  
std::ostream&amp; print(const json&amp; val, const output_format&lt;CharT&gt;&amp; format)  
</code></pre>

<p>Inserts json value into stream using the specified <a href="output_format">output_format</a> if supplied.</p>

<pre><code>std::ostream&amp; pretty_print(const json&amp; val)  
std::ostream&amp; pretty_print(const json&amp; val, const output_format&lt;CharT&gt;&amp; format)  
</code></pre>

<p>Inserts json value into stream using the specified <a href="output_format">output_format</a> if supplied.</p>

<pre><code>void swap(json&amp; a, json&amp; b)
</code></pre>

<p>Exchanges the values of <code>a</code> and <code>b</code></p>

<h3>Deprecated names</h3>

<p>As the <code>jsoncons</code> library has evolved, names have sometimes changed. To ease transition, jsoncons deprecates the old names but continues to support many of them. See the <a href="deprecated">deprecated list</a> for the status of old names. The deprecated names can be suppressed by defining macro JSONCONS_NO_DEPRECATED, which is recommended for new code.</p>

<h2>Examples</h2>

<h3>Range-based for loop over members of an object</h3>

<div class="highlight highlight-source-c++"><pre>    json book = json::parse(R<span class="pl-s"><span class="pl-pds">"</span>(</span>
<span class="pl-s">    {</span>
<span class="pl-s">        <span class="pl-pds">"</span></span>category<span class="pl-s"><span class="pl-pds">"</span> : <span class="pl-pds">"</span></span>Fiction<span class="pl-s"><span class="pl-pds">"</span>,</span>
<span class="pl-s">        <span class="pl-pds">"</span></span>title<span class="pl-s"><span class="pl-pds">"</span> : <span class="pl-pds">"</span></span>Pulp<span class="pl-s"><span class="pl-pds">"</span>,</span>
<span class="pl-s">        <span class="pl-pds">"</span></span>author<span class="pl-s"><span class="pl-pds">"</span> : <span class="pl-pds">"</span></span>Charles Bukowski<span class="pl-s"><span class="pl-pds">"</span>,</span>
<span class="pl-s">        <span class="pl-pds">"</span></span>date<span class="pl-s"><span class="pl-pds">"</span> : <span class="pl-pds">"</span></span><span class="pl-c1">2004</span>-<span class="pl-c1">07</span>-<span class="pl-c1">08</span><span class="pl-s"><span class="pl-pds">"</span>,</span>
<span class="pl-s">        <span class="pl-pds">"</span></span>price<span class="pl-s"><span class="pl-pds">"</span> : 22.48,</span>
<span class="pl-s">        <span class="pl-pds">"</span></span>isbn<span class="pl-s"><span class="pl-pds">"</span> : <span class="pl-pds">"</span></span><span class="pl-c1">1852272007</span><span class="pl-s"><span class="pl-pds">"</span>  </span>
<span class="pl-s">    }</span>
<span class="pl-s">    )<span class="pl-pds">"</span></span>);

    <span class="pl-k">for</span> (<span class="pl-k">auto</span> member: book.members())
    {
        std::cout &lt;&lt; member.<span class="pl-c1">name</span>() &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>:<span class="pl-pds">"</span></span> &lt;&lt; member.<span class="pl-c1">value</span>().<span class="pl-smi">as</span>&lt;string&gt;() &lt;&lt; std::endl;
    } </pre></div>

<h3>Range-based for loop over elements of an array</h3>

<div class="highlight highlight-source-c++"><pre>    json book1;    
    book1[<span class="pl-s"><span class="pl-pds">"</span>category<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Fiction<span class="pl-pds">"</span></span>;
    book1[<span class="pl-s"><span class="pl-pds">"</span>title<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>A Wild Sheep Chase: A Novel<span class="pl-pds">"</span></span>;
    book1[<span class="pl-s"><span class="pl-pds">"</span>author<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Haruki Murakami<span class="pl-pds">"</span></span>;

    json book2;    
    book2[<span class="pl-s"><span class="pl-pds">"</span>category<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>History<span class="pl-pds">"</span></span>;
    book2[<span class="pl-s"><span class="pl-pds">"</span>title<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Charlie Wilson's War<span class="pl-pds">"</span></span>;
    book2[<span class="pl-s"><span class="pl-pds">"</span>author<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>George Crile<span class="pl-pds">"</span></span>;

    json book3;    
    book3[<span class="pl-s"><span class="pl-pds">"</span>category<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Fiction<span class="pl-pds">"</span></span>;
    book3[<span class="pl-s"><span class="pl-pds">"</span>title<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Kafka on the Shore<span class="pl-pds">"</span></span>;
    book3[<span class="pl-s"><span class="pl-pds">"</span>author<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Haruki Murakami<span class="pl-pds">"</span></span>;

    <span class="pl-c">// Constructing a json array with an initializer list </span>
    json booklist = {book1, book2, book3};    

    <span class="pl-k">for</span> (<span class="pl-k">auto</span> book: booklist.elements())
    {
        std::cout &lt;&lt; book[<span class="pl-s"><span class="pl-pds">"</span>title<span class="pl-pds">"</span></span>].<span class="pl-smi">as</span>&lt;string_type&gt;() &lt;&lt; std::end;
    } </pre></div>

<h3>Accessors and defaults</h3>

<div class="highlight highlight-source-c++"><pre>    json obj;

    obj[<span class="pl-s"><span class="pl-pds">"</span>field1<span class="pl-pds">"</span></span>] = <span class="pl-c1">1</span>;
    obj[<span class="pl-s"><span class="pl-pds">"</span>field3<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Toronto<span class="pl-pds">"</span></span>;

    <span class="pl-k">double</span> x1 = obj.count(<span class="pl-s"><span class="pl-pds">"</span>field1<span class="pl-pds">"</span></span>) &gt; <span class="pl-c1">0</span> ? obj[<span class="pl-s"><span class="pl-pds">"</span>field1<span class="pl-pds">"</span></span>].as&lt;<span class="pl-k">double</span>&gt;() : <span class="pl-c1">10.0</span>;
    <span class="pl-k">double</span> x2 = obj.count(<span class="pl-s"><span class="pl-pds">"</span>field2<span class="pl-pds">"</span></span>) &gt; <span class="pl-c1">0</span> ? obj[<span class="pl-s"><span class="pl-pds">"</span>field2<span class="pl-pds">"</span></span>].as&lt;<span class="pl-k">double</span>&gt;() : <span class="pl-c1">20.0</span>;

    string_type x3 = obj.get(<span class="pl-s"><span class="pl-pds">"</span>field3<span class="pl-pds">"</span></span>,<span class="pl-s"><span class="pl-pds">"</span>Montreal<span class="pl-pds">"</span></span>).as&lt;string_type&gt;();
    string_type x4 = obj.get(<span class="pl-s"><span class="pl-pds">"</span>field4<span class="pl-pds">"</span></span>,<span class="pl-s"><span class="pl-pds">"</span>San Francisco<span class="pl-pds">"</span></span>).as&lt;string_type&gt;();

    std::cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>x1=<span class="pl-pds">"</span></span> &lt;&lt; x1 &lt;&lt; std::endl;
    std::cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>x2=<span class="pl-pds">"</span></span> &lt;&lt; x2 &lt;&lt; std::endl;
    std::cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>x3=<span class="pl-pds">"</span></span> &lt;&lt; x3 &lt;&lt; std::endl;
    std::cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>x4=<span class="pl-pds">"</span></span> &lt;&lt; x4 &lt;&lt; std::endl;</pre></div>

<p>The output is</p>

<div class="highlight highlight-source-c++"><pre>    x1=<span class="pl-c1">1</span>
    x2=<span class="pl-c1">20</span>
    x3=Toronto
    x4=San Francisco</pre></div>

<h3>Nulls</h3>

<div class="highlight highlight-source-c++"><pre>    json obj;
    obj[<span class="pl-s"><span class="pl-pds">"</span>field1<span class="pl-pds">"</span></span>] = json::null_type();
    std::cout &lt;&lt; obj &lt;&lt; std::endl;</pre></div>

<p>The output is </p>

<div class="highlight highlight-source-json"><pre>    {<span class="pl-s"><span class="pl-pds">"</span>field1<span class="pl-pds">"</span></span>:<span class="pl-c1">null</span>}</pre></div>

<h3>Array</h3>

<div class="highlight highlight-source-c++"><pre>    json arr = json::make_array();
    arr.add(<span class="pl-c1">10</span>);
    arr.add(<span class="pl-c1">20</span>);
    arr.add(<span class="pl-c1">30</span>);

    std::cout &lt;&lt; arr &lt;&lt; std::endl;</pre></div>

<p>The output is </p>

<div class="highlight highlight-source-json"><pre>    [<span class="pl-c1">10</span>,<span class="pl-c1">20</span>,<span class="pl-c1">30</span>]</pre></div>

<h3>Array from std::vector</h3>

<div class="highlight highlight-source-c++"><pre>    std::vector&lt;<span class="pl-k">int</span>&gt; v;
    v.push_back(<span class="pl-c1">10</span>);
    v.push_back(<span class="pl-c1">20</span>);
    v.push_back(<span class="pl-c1">30</span>);

    json <span class="pl-en">arr</span>(v.begin(),v.end());

    std::cout &lt;&lt; arr &lt;&lt; std::endl;</pre></div>

<p>The output is </p>

<div class="highlight highlight-source-c++"><pre>    [<span class="pl-c1">10</span>,<span class="pl-c1">20</span>,<span class="pl-c1">30</span>]</pre></div>

<h3>Object iterator</h3>

<div class="highlight highlight-source-c++"><pre>    json obj;
    obj[<span class="pl-s"><span class="pl-pds">"</span>city<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Toronto<span class="pl-pds">"</span></span>;
    obj[<span class="pl-s"><span class="pl-pds">"</span>province<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Ontario<span class="pl-pds">"</span></span>;
    obj[<span class="pl-s"><span class="pl-pds">"</span>country<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Canada<span class="pl-pds">"</span></span>;

    <span class="pl-k">for</span> (<span class="pl-k">auto</span> it = obj.members().begin(); it != obj.members().end(); ++it)
    {
        std::cout &lt;&lt; it-&gt;<span class="pl-c1">name</span>() &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>=<span class="pl-pds">"</span></span> &lt;&lt; it-&gt;<span class="pl-c1">value</span>().<span class="pl-smi">as</span>&lt;string_type&gt;() &lt;&lt; std::endl;
    }</pre></div>

<p>The output is</p>

<div class="highlight highlight-source-c++"><pre>    city=Toronto
    country=Canada
    province=Ontario</pre></div>

<h3>Array iterator</h3>

<div class="highlight highlight-source-c++"><pre>    json arr = {<span class="pl-s"><span class="pl-pds">"</span>Toronto<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>Vancouver<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>Montreal<span class="pl-pds">"</span></span>};

    <span class="pl-k">for</span> (<span class="pl-k">auto</span> it = arr.elements().begin(); it != arr.elements().end(); ++it)
    {
        std::cout &lt;&lt; it-&gt;as&lt;string_type&gt;() &lt;&lt; std::endl;
    }</pre></div>

<p>The output is</p>

<div class="highlight highlight-source-json"><pre>    Toronto
    Vancouver 
    Montreal</pre></div>

<h3>Constructing json structures</h3>

<div class="highlight highlight-source-c++"><pre>    json root;

    root[<span class="pl-s"><span class="pl-pds">"</span>persons<span class="pl-pds">"</span></span>] = json::make_array();

    json person;
    person[<span class="pl-s"><span class="pl-pds">"</span>first_name<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>John<span class="pl-pds">"</span></span>;
    person[<span class="pl-s"><span class="pl-pds">"</span>last_name<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Smith<span class="pl-pds">"</span></span>;
    person[<span class="pl-s"><span class="pl-pds">"</span>birth_date<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>1972-01-30<span class="pl-pds">"</span></span>;

    json address;
    address[<span class="pl-s"><span class="pl-pds">"</span>city<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Toronto<span class="pl-pds">"</span></span>;
    address[<span class="pl-s"><span class="pl-pds">"</span>country<span class="pl-pds">"</span></span>] = <span class="pl-s"><span class="pl-pds">"</span>Canada<span class="pl-pds">"</span></span>;

    person[<span class="pl-s"><span class="pl-pds">"</span>address<span class="pl-pds">"</span></span>] = std::move(address);

    root[<span class="pl-s"><span class="pl-pds">"</span>persons<span class="pl-pds">"</span></span>].add(std::move(person));

    std::cout &lt;&lt; pretty_print(root) &lt;&lt; std::endl;</pre></div>

<p>The output is</p>

<div class="highlight highlight-source-c++"><pre>    {
        <span class="pl-s"><span class="pl-pds">"</span>persons<span class="pl-pds">"</span></span>:
        [
            {
                <span class="pl-s"><span class="pl-pds">"</span>address<span class="pl-pds">"</span></span>:
                {
                    <span class="pl-s"><span class="pl-pds">"</span>city<span class="pl-pds">"</span></span>:<span class="pl-s"><span class="pl-pds">"</span>Toronto<span class="pl-pds">"</span></span>,
                    <span class="pl-s"><span class="pl-pds">"</span>country<span class="pl-pds">"</span></span>:<span class="pl-s"><span class="pl-pds">"</span>Canada<span class="pl-pds">"</span></span>
                },
                <span class="pl-s"><span class="pl-pds">"</span>birth_date<span class="pl-pds">"</span></span>:<span class="pl-s"><span class="pl-pds">"</span>1972-01-30<span class="pl-pds">"</span></span>,
                <span class="pl-s"><span class="pl-pds">"</span>first_name<span class="pl-pds">"</span></span>:<span class="pl-s"><span class="pl-pds">"</span>John<span class="pl-pds">"</span></span>,
                <span class="pl-s"><span class="pl-pds">"</span>last_name<span class="pl-pds">"</span></span>:<span class="pl-s"><span class="pl-pds">"</span>Smith<span class="pl-pds">"</span></span>
            }
        ]
    }</pre></div>
</body>
</html>
<!-- This document was created with MarkdownPad, the Markdown editor for Windows (http://markdownpad.com) -->
