mirror of
https://github.com/nlohmann/json.git
synced 2026-10-08 07:27:12 +00:00
deploy: 48e7b4c23b
This commit is contained in:
1 parent
c818701d98
commit
a40ca752f0
2 files changed
+2
-2
No files matched your search
@@ -11,7 +11,7 @@
|
||||
<span class=k>static</span><span class=w> </span><span class=kt>void</span><span class=w> </span><span class=nf>to_bjdata</span><span class=p>(</span><span class=k>const</span><span class=w> </span><span class=n>basic_json</span><span class=o>&</span><span class=w> </span><span class=n>j</span><span class=p>,</span><span class=w> </span><span class=n>detail</span><span class=o>::</span><span class=n>output_adapter</span><span class=o><</span><span class=kt>char</span><span class=o>></span><span class=w> </span><span class=n>o</span><span class=p>,</span>
|
||||
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=n>use_size</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=nb>false</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=n>use_type</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=nb>false</span><span class=p>,</span>
|
||||
<span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>bjdata_version_t</span><span class=w> </span><span class=n>version</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>bjdata_version_t</span><span class=o>::</span><span class=n>draft2</span><span class=p>);</span>
|
||||
</code></pre></div> <p>Serializes a given JSON value <code>j</code> to a byte vector using the BJData (Binary JData) serialization format. BJData aims to be more compact than JSON itself, yet more efficient to parse.</p> <ol> <li>Returns a byte vector containing the BJData serialization.</li> <li>Writes the BJData serialization to an output adapter.</li> </ol> <p>The exact mapping and its limitations is described on a <a href=../../../features/binary_formats/bjdata/ >dedicated page</a>.</p> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">¶</a></h2> <dl> <dt><code>j</code> (in)</dt> <dd>JSON value to serialize</dd> <dt><code>o</code> (in)</dt> <dd>output adapter to write serialization to</dd> <dt><code>use_size</code> (in)</dt> <dd>whether to add size annotations to container types; optional, <code class=highlight><span class=nb>false</span></code> by default.</dd> <dt><code>use_type</code> (in)</dt> <dd>whether to add type annotations to container types (must be combined with <code class=highlight><span class=n>use_size</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=nb>true</span></code>); optional,</dd> <dt><code>version</code> (in)</dt> <dd>which version of BJData to use (see <a href=../../../features/binary_formats/bjdata/#draft-3-binary-format>draft 3</a>); optional, <code class=highlight><span class=nb>false</span></code> by default.</dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">¶</a></h2> <ol> <li>BJData serialization as byte vector</li> <li>(none)</li> </ol> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">¶</a></h2> <p>Strong guarantee: if an exception is thrown, there are no changes in the JSON value.</p> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">¶</a></h2> <p>Linear in the size of the JSON value <code>j</code>.</p> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">¶</a></h2> <details class=example> <summary>Example</summary> <p>The example shows the serialization of a JSON value to a byte vector in BJData format.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf><iostream></span>
|
||||
</code></pre></div> <p>Serializes a given JSON value <code>j</code> to a byte vector using the BJData (Binary JData) serialization format. BJData aims to be more compact than JSON itself, yet more efficient to parse.</p> <ol> <li>Returns a byte vector containing the BJData serialization.</li> <li>Writes the BJData serialization to an output adapter.</li> </ol> <p>The exact mapping and its limitations is described on a <a href=../../../features/binary_formats/bjdata/ >dedicated page</a>.</p> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">¶</a></h2> <dl> <dt><code>j</code> (in)</dt> <dd>JSON value to serialize</dd> <dt><code>o</code> (in)</dt> <dd>output adapter to write serialization to</dd> <dt><code>use_size</code> (in)</dt> <dd>whether to add size annotations to container types; optional, <code class=highlight><span class=nb>false</span></code> by default.</dd> <dt><code>use_type</code> (in)</dt> <dd>whether to add type annotations to container types (must be combined with <code class=highlight><span class=n>use_size</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=nb>true</span></code>); optional, <code class=highlight><span class=nb>false</span></code> by default.</dd> <dt><code>version</code> (in)</dt> <dd>which version of BJData to use (see <a href=../../../features/binary_formats/bjdata/#draft-3-binary-format>draft 3</a>); optional, <code class=highlight><span class=n>bjdata_version_t</span><span class=o>::</span><span class=n>draft2</span></code> by default.</dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">¶</a></h2> <ol> <li>BJData serialization as byte vector</li> <li>(none)</li> </ol> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">¶</a></h2> <p>Strong guarantee: if an exception is thrown, there are no changes in the JSON value.</p> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">¶</a></h2> <p>Linear in the size of the JSON value <code>j</code>.</p> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">¶</a></h2> <details class=example> <summary>Example</summary> <p>The example shows the serialization of a JSON value to a byte vector in BJData format.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf><iostream></span>
|
||||
<span class=cp>#include</span><span class=w> </span><span class=cpf><iomanip></span>
|
||||
<span class=cp>#include</span><span class=w> </span><span class=cpf><nlohmann/json.hpp></span>
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"config":{"lang":["en"],"separator":"[\\s\\-\\.]","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"JSON for Modern C++","text":""},{"location":"api/json/","title":"nlohmann::json","text":"<pre><code>using json = basic_json<>;\n</code></pre> <p>This type is the default specialization of the basic_json class which uses the standard template types.</p>"},{"location":"api/json/#examples","title":"Examples","text":"Example <p>The example below demonstrates how to use the type <code>nlohmann::json</code>.</p> <pre><code>#include <iostream>\n#include <iomanip>\n#include <nlohmann/json.hpp>\n\nusing json = nlohmann::json;\n\nint main()\n{\n // create a JSON object\n json j =\n {\n {\"pi\", 3.141},\n {\"happy\", true},\n {\"name\", \"Niels\"},\n {\"nothing\", nullptr},\n {\n \"answer\", {\n {\"everything\", 42}\n }\n },\n {\"list\", {1, 0, 2}},\n {\n \"object\", {\n {\"currency\", \"USD\"},\n {\"value\", 42.99}\n }\n }\n };\n\n // add new values\n j[\"new\"][\"key\"][\"value\"] = {\"another\", \"list\"};\n\n // count elements\n auto s = j.size();\n j[\"size\"] = s;\n\n // pretty print with indent of 4 spaces\n std::cout << std::setw(4) << j << '\\n';\n}\n</code></pre> <p>Output:</p> <pre><code>{\n \"answer\": {\n \"everything\": 42\n },\n \"happy\": true,\n \"list\": [\n 1,\n 0,\n 2\n ],\n \"name\": \"Niels\",\n \"new\": {\n \"key\": {\n \"value\": [\n \"another\",\n \"list\"\n ]\n }\n },\n \"nothing\": null,\n \"object\": {\n \"currency\": \"USD\",\n \"value\": 42.99\n },\n \"pi\": 3.141,\n \"size\": 8\n}\n</code></pre>"},{"location":"api/json/#version-history","title":"Version history","text":"<p>Since version 1.0.0.</p>"},{"location":"api/operator_gtgt/","title":"nlohmann::operator>>(basic_json)","text":"<pre><code>std::istream& operator>>(std::istream& i, basic_json& j);\n</code></pre> <p>Deserializes an input stream to a JSON value.</p>"},{"location":"api/operator_gtgt/#parameters","title":"Parameters","text":"<code>i</code> (in, out) input stream to read a serialized JSON value from <code>j</code> (in, out) JSON value to write the deserialized input to"},{"location":"api/operator_gtgt/#return-value","title":"Return value","text":"<p>the stream <code>i</code></p>"},{"location":"api/operator_gtgt/#exceptions","title":"Exceptions","text":"<ul> <li>Throws <code>parse_error.101</code> in case of an unexpected token.</li> <li>Throws <code>parse_error.102</code> if to_unicode fails or surrogate error.</li> <li>Throws <code>parse_error.103</code> if to_unicode fails.</li> </ul>"},{"location":"api/operator_gtgt/#complexity","title":"Complexity","text":"<p>Linear in the length of the input. The parser is a predictive LL(1) parser.</p>"},{"location":"api/operator_gtgt/#notes","title":"Notes","text":"<p>A UTF-8 byte order mark is silently ignored.</p> <p>Deprecation</p> <p>This function replaces function <code>std::istream& operator<<(basic_json& j, std::istream& i)</code> which has been deprecated in version 3.0.0. It will be removed in version 4.0.0. Please replace calls like <code>j << i;</code> with <code>i >> j;</code>.</p>"},{"location":"api/operator_gtgt/#examples","title":"Examples","text":"Example <p>The example below shows how a JSON value is constructed by reading a serialization from a stream.</p> <pre><code>#include <iostream>\n#include <iomanip>\n#include <sstream>\n#include <nlohmann/json.hpp>\n\nusing json = nlohmann::json;\n\nint main()\n{\n // create stream with serialized JSON\n std::stringstream ss;\n ss << R\"({\n \"number\": 23,\n \"string\": \"Hello, world!\",\n \"array\": [1, 2, 3, 4, 5],\n \"boolean\": false,\n \"null\": null\n })\";\n\n // create JSON value and read the serialization from the stream\n json j;\n ss >> j;\n\n // serialize JSON\n std::cout << std::setw(2) << j << '\\n';\n}\n</code></pre> <p>Output:</p> <pre><code>{\n \"array\": [\n 1,\n 2,\n 3,\n 4,\n 5\n ],\n \"boolean\": false,\n \"null\": null,\n \"number\": 23,\n \"string\": \"Hello, world!\"\n}\n</code></pre>"},{"location":"api/operator_gtgt/#see-also","title":"See also","text":"<ul> <li>accept - check if the input is valid JSON</li> <li>parse - deserialize from a compatible input</li> </ul>"},{"location":"api/operator_gtgt/#version-history","title":"Version history","text":"<ul> <li>Added in version 1.0.0. Deprecated in version 3.0.0.</li> </ul>"},{"location":"api/operator_literal_json/","title":"nlohmann::operator\"\"_json","text":"<pre><code>json operatorLine truncated
|
||||
{"config":{"lang":["en"],"separator":"[\\s\\-\\.]","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"JSON for Modern C++","text":""},{"location":"api/json/","title":"nlohmann::json","text":"<pre><code>using json = basic_json<>;\n</code></pre> <p>This type is the default specialization of the basic_json class which uses the standard template types.</p>"},{"location":"api/json/#examples","title":"Examples","text":"Example <p>The example below demonstrates how to use the type <code>nlohmann::json</code>.</p> <pre><code>#include <iostream>\n#include <iomanip>\n#include <nlohmann/json.hpp>\n\nusing json = nlohmann::json;\n\nint main()\n{\n // create a JSON object\n json j =\n {\n {\"pi\", 3.141},\n {\"happy\", true},\n {\"name\", \"Niels\"},\n {\"nothing\", nullptr},\n {\n \"answer\", {\n {\"everything\", 42}\n }\n },\n {\"list\", {1, 0, 2}},\n {\n \"object\", {\n {\"currency\", \"USD\"},\n {\"value\", 42.99}\n }\n }\n };\n\n // add new values\n j[\"new\"][\"key\"][\"value\"] = {\"another\", \"list\"};\n\n // count elements\n auto s = j.size();\n j[\"size\"] = s;\n\n // pretty print with indent of 4 spaces\n std::cout << std::setw(4) << j << '\\n';\n}\n</code></pre> <p>Output:</p> <pre><code>{\n \"answer\": {\n \"everything\": 42\n },\n \"happy\": true,\n \"list\": [\n 1,\n 0,\n 2\n ],\n \"name\": \"Niels\",\n \"new\": {\n \"key\": {\n \"value\": [\n \"another\",\n \"list\"\n ]\n }\n },\n \"nothing\": null,\n \"object\": {\n \"currency\": \"USD\",\n \"value\": 42.99\n },\n \"pi\": 3.141,\n \"size\": 8\n}\n</code></pre>"},{"location":"api/json/#version-history","title":"Version history","text":"<p>Since version 1.0.0.</p>"},{"location":"api/operator_gtgt/","title":"nlohmann::operator>>(basic_json)","text":"<pre><code>std::istream& operator>>(std::istream& i, basic_json& j);\n</code></pre> <p>Deserializes an input stream to a JSON value.</p>"},{"location":"api/operator_gtgt/#parameters","title":"Parameters","text":"<code>i</code> (in, out) input stream to read a serialized JSON value from <code>j</code> (in, out) JSON value to write the deserialized input to"},{"location":"api/operator_gtgt/#return-value","title":"Return value","text":"<p>the stream <code>i</code></p>"},{"location":"api/operator_gtgt/#exceptions","title":"Exceptions","text":"<ul> <li>Throws <code>parse_error.101</code> in case of an unexpected token.</li> <li>Throws <code>parse_error.102</code> if to_unicode fails or surrogate error.</li> <li>Throws <code>parse_error.103</code> if to_unicode fails.</li> </ul>"},{"location":"api/operator_gtgt/#complexity","title":"Complexity","text":"<p>Linear in the length of the input. The parser is a predictive LL(1) parser.</p>"},{"location":"api/operator_gtgt/#notes","title":"Notes","text":"<p>A UTF-8 byte order mark is silently ignored.</p> <p>Deprecation</p> <p>This function replaces function <code>std::istream& operator<<(basic_json& j, std::istream& i)</code> which has been deprecated in version 3.0.0. It will be removed in version 4.0.0. Please replace calls like <code>j << i;</code> with <code>i >> j;</code>.</p>"},{"location":"api/operator_gtgt/#examples","title":"Examples","text":"Example <p>The example below shows how a JSON value is constructed by reading a serialization from a stream.</p> <pre><code>#include <iostream>\n#include <iomanip>\n#include <sstream>\n#include <nlohmann/json.hpp>\n\nusing json = nlohmann::json;\n\nint main()\n{\n // create stream with serialized JSON\n std::stringstream ss;\n ss << R\"({\n \"number\": 23,\n \"string\": \"Hello, world!\",\n \"array\": [1, 2, 3, 4, 5],\n \"boolean\": false,\n \"null\": null\n })\";\n\n // create JSON value and read the serialization from the stream\n json j;\n ss >> j;\n\n // serialize JSON\n std::cout << std::setw(2) << j << '\\n';\n}\n</code></pre> <p>Output:</p> <pre><code>{\n \"array\": [\n 1,\n 2,\n 3,\n 4,\n 5\n ],\n \"boolean\": false,\n \"null\": null,\n \"number\": 23,\n \"string\": \"Hello, world!\"\n}\n</code></pre>"},{"location":"api/operator_gtgt/#see-also","title":"See also","text":"<ul> <li>accept - check if the input is valid JSON</li> <li>parse - deserialize from a compatible input</li> </ul>"},{"location":"api/operator_gtgt/#version-history","title":"Version history","text":"<ul> <li>Added in version 1.0.0. Deprecated in version 3.0.0.</li> </ul>"},{"location":"api/operator_literal_json/","title":"nlohmann::operator\"\"_json","text":"<pre><code>json operatorLine truncated
|
||||
Reference in new issue
Block a user