| 46 | } |
| 47 | |
| 48 | void parse_with_trailing_commas() |
| 49 | { |
| 50 | std::string s = R"( |
| 51 | { |
| 52 | "first" : 1, |
| 53 | "second" : 2, |
| 54 | } |
| 55 | )"; |
| 56 | |
| 57 | // Default |
| 58 | try |
| 59 | { |
| 60 | auto j = json::parse(s); |
| 61 | } |
| 62 | catch (const ser_error& e) |
| 63 | { |
| 64 | std::cout << "(1) " << e.what() << "\n\n"; |
| 65 | } |
| 66 | |
| 67 | // Allow trailing commas |
| 68 | |
| 69 | // until 0.170.0 |
| 70 | // auto j = json::parse(s, allow_trailing_commas()); |
| 71 | |
| 72 | // since 0.170.0 |
| 73 | // auto options = json_options{} |
| 74 | // .err_handler(allow_trailing_commas()); |
| 75 | // auto j = json::parse(s, options); |
| 76 | |
| 77 | // since 1.3.0 |
| 78 | auto options = json_options{} |
| 79 | .allow_trailing_comma(true); |
| 80 | auto j = json::parse(s, options); |
| 81 | std::cout << "(2) " << j << "\n\n"; |
| 82 | } |
| 83 | |
| 84 | void parse_error_example() |
| 85 | { |
no test coverage detected