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

Function encode_m_columns

examples/src/csv_examples.cpp:92–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92void encode_m_columns()
93{
94 const std::string jtext = R"(
95{
96 "customer_name": ["John Roe","Jane Doe","Joe Bloggs","John Smith"],
97 "has_coupon": [true,false,false,false],
98 "phone_number": ["0272561313","416-272-2561","4162722561",null],
99 "zip_code": ["01001","55416","55416","22313-1450"],
100 "sales_tax_rate": [0.05,0.15,0.15,0.15],
101 "total_amount": [431.65,480.7,300.7,300.7]
102}
103 )";
104
105 auto j = jsoncons::ojson::parse(jtext);
106
107 std::string output;
108 auto ioptions = csv::csv_options{}
109 .quote_style(csv::quote_style_kind::nonnumeric);
110 csv::encode_csv(j, output, ioptions);
111 std::cout << output << "\n\n";
112
113 auto ooptions = csv::csv_options{}
114 .assume_header(true)
115 .mapping_kind(csv::csv_mapping_kind::m_columns);
116 auto other = csv::decode_csv<jsoncons::ojson>(output, ooptions);
117 assert(other == j);
118}
119
120void csv_source_to_json_value()
121{

Callers 1

mainFunction · 0.85

Calls 5

parseFunction · 0.85
encode_csvFunction · 0.85
quote_styleMethod · 0.80
mapping_kindMethod · 0.80
assume_headerMethod · 0.80

Tested by

no test coverage detected