MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / parse_with_trailing_commas

Function parse_with_trailing_commas

examples/src/json_parse_examples.cpp:48–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48void 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
84void parse_error_example()
85{

Callers 1

mainFunction · 0.85

Calls 3

parseFunction · 0.85
allow_trailing_commaMethod · 0.80
whatMethod · 0.45

Tested by

no test coverage detected