@@ -142,7 +142,7 @@ behavior.
142142>
143143> ```c++
144144> dom::element doc;
145- > error_code error;
145+ > simdjson:: error_code error;
146146> parser.parse(json).tie(doc, error); // <-- Assigns to doc and error just like "auto [doc, error]"
147147> ```
148148
@@ -152,48 +152,50 @@ This is how the example in "Using the Parsed JSON" could be written using only e
152152
153153```c++
154154auto cars_json = R"( [
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 ] }
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 ] }
158158] )"_padded;
159159dom::parser parser;
160- auto [doc , error] = parser.parse(cars_json);
160+ auto [cars , error] = parser.parse(cars_json).get<dom::array>( );
161161if (error) { cerr << error << endl; exit(1); }
162162
163163// Iterating through an array of objects
164164for (dom::element car_element : cars) {
165- dom::object car;
166- car_element.get<dom::object>().tie(car, error);
167- 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); }
168168
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;
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;
176176
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;
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;
182182
183- // Iterating through an array of floats
184- double total_tire_pressure = 0;
185- 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) {
186189 double tire_pressure;
187- tire_pressure_element.get<uint64_t >().tie(tire_pressure, error);
190+ tire_pressure_element.get<double >().tie(tire_pressure, error);
188191 if (error) { cerr << error << endl; exit(1); }
189192 total_tire_pressure += tire_pressure;
190- }
191- cout << "- Average tire pressure: " << (total_tire_pressure / 4) << endl;
193+ }
194+ cout << "- Average tire pressure: " << (total_tire_pressure / 4) << endl;
192195
193- // Writing out all the information about the car
194- for (auto [key, value] : car) {
196+ // Writing out all the information about the car
197+ for (auto [key, value] : car) {
195198 cout << "- " << key << ": " << value << endl;
196- }
197199}
198200```
199201
@@ -217,14 +219,15 @@ format. If your JSON documents all contain arrays or objects, we even support di
217219concatenation without whitespace. The concatenated file has no size restrictions (including larger
218220than 4GB), though each individual document must be less than 4GB.
219221
220- Here is a simple example:
222+ Here is a simple example, given "x.json" with this content :
221223
222- ``` cpp
223- auto ndjson = R"(
224+ ``` json
224225{ "foo" : 1 }
225226{ "foo" : 2 }
226227{ "foo" : 3 }
227- )" _padded;
228+ ```
229+
230+ ``` c++
228231dom::parser parser;
229232for (dom::element doc : parser.load_many(filename)) {
230233 cout << doc[ "foo"] << endl;
0 commit comments