| 13 | namespace csv = jsoncons::csv; |
| 14 | |
| 15 | void encode_n_objects() |
| 16 | { |
| 17 | const std::string jtext = R"( |
| 18 | [ |
| 19 | { |
| 20 | "customer_name": "John Roe", |
| 21 | "has_coupon": true, |
| 22 | "phone_number": "0272561313", |
| 23 | "zip_code": "01001", |
| 24 | "sales_tax_rate": 0.05, |
| 25 | "total_amount": 431.65 |
| 26 | }, |
| 27 | { |
| 28 | "customer_name": "Jane Doe", |
| 29 | "has_coupon": false, |
| 30 | "phone_number": "416-272-2561", |
| 31 | "zip_code": "55416", |
| 32 | "sales_tax_rate": 0.15, |
| 33 | "total_amount": 480.7 |
| 34 | }, |
| 35 | { |
| 36 | "customer_name": "Joe Bloggs", |
| 37 | "has_coupon": false, |
| 38 | "phone_number": "4162722561", |
| 39 | "zip_code": "55416", |
| 40 | "sales_tax_rate": 0.15, |
| 41 | "total_amount": 300.7 |
| 42 | }, |
| 43 | { |
| 44 | "customer_name": "John Smith", |
| 45 | "has_coupon": false, |
| 46 | "phone_number": null, |
| 47 | "zip_code": "22313-1450", |
| 48 | "sales_tax_rate": 0.15, |
| 49 | "total_amount": 300.7 |
| 50 | } |
| 51 | ] |
| 52 | )"; |
| 53 | |
| 54 | auto j = jsoncons::ojson::parse(jtext); |
| 55 | |
| 56 | std::string output; |
| 57 | auto ioptions = csv::csv_options{} |
| 58 | .quote_style(csv::quote_style_kind::nonnumeric); |
| 59 | csv::encode_csv(j, output, ioptions); |
| 60 | std::cout << output << "\n\n"; |
| 61 | |
| 62 | auto ooptions = csv::csv_options{} |
| 63 | .assume_header(true); |
| 64 | auto other = csv::decode_csv<jsoncons::ojson>(output, ooptions); |
| 65 | assert(other == j); |
| 66 | } |
| 67 | |
| 68 | void encode_n_rows() |
| 69 | { |
no test coverage detected