mirror of
https://github.com/nlohmann/json.git
synced 2026-10-07 15:07:13 +00:00
deploy: 23518f54fe
This commit is contained in:
1 parent
b2dfbf8855
commit
b4e4dbe346
262 files changed
+819
-742
No files matched your search
@@ -1 +1 @@
|
||||
{"config":{"lang":["en"],"separator":"[\\s\\-\\.]","pipeline":["stopWordFilter"],"fields":{"title":{"boost":1000.0},"text":{"boost":1.0},"tags":{"boost":1000000.0}}},"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> </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>Invalid Unicode escapes and unpaired surrogates in the input are reported as <code>parse_error.101</code> with a detailed message.</p> <p><code>operator>></code> parses exactly one JSON value, so it can be called repeatedly to read a sequence of concatenated JSON values from the same stream:</p> <pre><code>json j1, j2;\ninput >> j1; // parses the first value\ninput >> j2; // parses the next value\n</code></pre> <p>A number must be followed by whitespace</p> <p>A number is only terminated by the character that follows it. That character is read from the stream to detect the end of the number, and it is not put back. When a value that is a number is immediately followed by the next value, the first character of that next value is lost:</p> <pre><code>std::istringstream input(\"1true\");\njson j1, j2;\ninput >> j1; // j1 == 1\ninput >> j2; // throws parse_error.101: the stream now starts at \"rue\"\n</code></pre> <p>Separating the values with whitespace avoids this, because the character that is eaten is then the separator:</p> <pre><code>std::istringstream input(\"1 true\");\njson j1, j2;\ninput >> j1; // j1 == 1\ninput >> j2; // j2 == true\n</code></pre> <p>Only numbers are affected. Values ending in a self-delimiting character do not read past themselves, so <code>truefalse</code>, <code>[1][2]</code>, <code>{\"a\":1}{\"b\":2}</code>, and <code>\"a\"\"b\"</code> can be read back to back without a separator.</p> <p>This is tracked in #5340.</p> <p>Note that reading concatenated values does not work for JSON Lines (newline-delimited JSON) input -- see that page for why and for the recommended alternative.</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 3Line truncated
|
||||
{"config":{"lang":["en"],"separator":"[\\s\\-\\.]","pipeline":["stopWordFilter"],"fields":{"title":{"boost":1000.0},"text":{"boost":1.0},"tags":{"boost":1000000.0}}},"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> </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>Invalid Unicode escapes and unpaired surrogates in the input are reported as <code>parse_error.101</code> with a detailed message.</p> <p><code>operator>></code> parses exactly one JSON value, so it can be called repeatedly to read a sequence of concatenated JSON values from the same stream:</p> <pre><code>json j1, j2;\ninput >> j1; // parses the first value\ninput >> j2; // parses the next value\n</code></pre> <p>A number must be followed by whitespace</p> <p>A number is only terminated by the character that follows it. That character is read from the stream to detect the end of the number, and it is not put back. When a value that is a number is immediately followed by the next value, the first character of that next value is lost:</p> <pre><code>std::istringstream input(\"1true\");\njson j1, j2;\ninput >> j1; // j1 == 1\ninput >> j2; // throws parse_error.101: the stream now starts at \"rue\"\n</code></pre> <p>Separating the values with whitespace avoids this, because the character that is eaten is then the separator:</p> <pre><code>std::istringstream input(\"1 true\");\njson j1, j2;\ninput >> j1; // j1 == 1\ninput >> j2; // j2 == true\n</code></pre> <p>Only numbers are affected. Values ending in a self-delimiting character do not read past themselves, so <code>truefalse</code>, <code>[1][2]</code>, <code>{\"a\":1}{\"b\":2}</code>, and <code>\"a\"\"b\"</code> can be read back to back without a separator.</p> <p>This is tracked in #5340.</p> <p>Note that reading concatenated values does not work for JSON Lines (newline-delimited JSON) input -- see that page for why and for the recommended alternative.</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 3Line truncated
|
||||
Reference in new issue
Block a user