@@ -102,8 +102,6 @@ for (dom::object car : cars) {
102102}
103103```
104104
105-
106-
107105JSON Pointer
108106------------
109107
@@ -144,7 +142,7 @@ behavior.
144142>
145143> ```c++
146144> dom::element doc;
147- > error_code error;
145+ > simdjson:: error_code error;
148146> parser.parse(json).tie(doc, error); // <-- Assigns to doc and error just like "auto [doc, error]"
149147> ```
150148
@@ -154,48 +152,50 @@ This is how the example in "Using the Parsed JSON" could be written using only e
154152
155153```c++
156154auto cars_json = R"( [
157- { "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
158- { "make": "Kia", "model": "Soul", "year": 2012, "tire_pressure": [ 30.1, 31.0, 28.6, 28.7 ] },
159- { "make": "Toyota", "model": "Tercel", "year": 1999, "tire_pressure": [ 29.8, 30.0, 30.2, 30.5 ] }
155+ { "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
156+ { "make": "Kia", "model": "Soul", "year": 2012, "tire_pressure": [ 30.1, 31.0, 28.6, 28.7 ] },
157+ { "make": "Toyota", "model": "Tercel", "year": 1999, "tire_pressure": [ 29.8, 30.0, 30.2, 30.5 ] }
160158] )"_padded;
161159dom::parser parser;
162- auto [doc , error] = parser.parse(cars_json);
160+ auto [cars , error] = parser.parse(cars_json).get<dom::array>( );
163161if (error) { cerr << error << endl; exit(1); }
164162
165163// Iterating through an array of objects
166164for (dom::element car_element : cars) {
167- dom::object car;
168- car_element.get<dom::object>().tie(car, error);
169- if (error) { cerr << error << endl; exit(1); }
165+ dom::object car;
166+ car_element.get<dom::object>().tie(car, error);
167+ if (error) { cerr << error << endl; exit(1); }
170168
171- // Accessing a field by name
172- dom::element make, model;
173- car["make"].tie(make, error);
174- if (error) { cerr << error << endl; exit(1); }
175- car["model"].tie(model, error);
176- if (error) { cerr << error << endl; exit(1); }
177- cout << "Make/Model: " << make << "/" << model << endl;
169+ // Accessing a field by name
170+ dom::element make, model;
171+ car["make"].tie(make, error);
172+ if (error) { cerr << error << endl; exit(1); }
173+ car["model"].tie(model, error);
174+ if (error) { cerr << error << endl; exit(1); }
175+ cout << "Make/Model: " << make << "/" << model << endl;
178176
179- // Casting a JSON element to an integer
180- uint64_t year;
181- car["year"].get<uint64_t>().tie(year, error);
182- if (error) { cerr << error << endl; exit(1); }
183- cout << "- This car is " << 2020 - year << "years old." << endl;
177+ // Casting a JSON element to an integer
178+ uint64_t year;
179+ car["year"].get<uint64_t>().tie(year, error);
180+ if (error) { cerr << error << endl; exit(1); }
181+ cout << "- This car is " << 2020 - year << "years old." << endl;
184182
185- // Iterating through an array of floats
186- double total_tire_pressure = 0;
187- for (dom::element tire_pressure_element : car["tire_pressure"]) {
183+ // Iterating through an array of floats
184+ double total_tire_pressure = 0;
185+ dom::array tire_pressure_array;
186+ car["tire_pressure"].get<dom::array>().tie(tire_pressure_array, error);
187+ if (error) { cerr << error << endl; exit(1); }
188+ for (dom::element tire_pressure_element : tire_pressure_array) {
188189 double tire_pressure;
189- tire_pressure_element.get<uint64_t >().tie(tire_pressure, error);
190+ tire_pressure_element.get<double >().tie(tire_pressure, error);
190191 if (error) { cerr << error << endl; exit(1); }
191192 total_tire_pressure += tire_pressure;
192- }
193- cout << "- Average tire pressure: " << (total_tire_pressure / 4) << endl;
193+ }
194+ cout << "- Average tire pressure: " << (total_tire_pressure / 4) << endl;
194195
195- // Writing out all the information about the car
196- for (auto [key, value] : car) {
196+ // Writing out all the information about the car
197+ for (auto [key, value] : car) {
197198 cout << "- " << key << ": " << value << endl;
198- }
199199}
200200```
201201
@@ -215,14 +215,15 @@ Newline-Delimited JSON (ndjson) and JSON lines
215215
216216The simdjson library also support multithreaded JSON streaming through a large file containing many smaller JSON documents in either [ ndjson] ( http://ndjson.org ) or [ JSON lines] ( http://jsonlines.org ) format. If your JSON documents all contain arrays or objects, we even support direct file concatenation without whitespace. The concatenated file has no size restrictions (including larger than 4GB), though each individual document must be less than 4GB.
217217
218- Here is a simple example:
218+ Here is a simple example, given "x.json" with this content :
219219
220- ``` cpp
221- auto ndjson = R"(
220+ ``` json
222221{ "foo" : 1 }
223222{ "foo" : 2 }
224223{ "foo" : 3 }
225- )" _padded;
224+ ```
225+
226+ ``` c++
226227dom::parser parser;
227228for (dom::element doc : parser.load_many(filename)) {
228229 cout << doc[ "foo"] << endl;
0 commit comments