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

Function as_a_variant_like_structure

examples/src/csv_examples.cpp:540–563  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

538)";
539
540void as_a_variant_like_structure()
541{
542 auto options = csv::csv_options{}
543 .assume_header(true);
544
545 // Parse the CSV data into an ojson value
546 auto j = csv::decode_csv<jsoncons::ojson>(data, options);
547
548 // Pretty print
549 auto print_options = jsoncons::json_options{}
550 .float_format(jsoncons::float_chars_format::fixed);
551 std::cout << "(1)\n" << pretty_print(j, print_options) << "\n\n";
552
553 // Iterate over the rows
554 std::cout << std::fixed << std::setprecision(7);
555 std::cout << "(2)\n";
556 for (const auto& row : j.array_range())
557 {
558 // Access rated as string and rating as double
559 std::cout << row["index_id"].as<std::string>() << ", "
560 << row["observation_date"].as<std::string>() << ", "
561 << row["rate"].as<double>() << "\n";
562 }
563}
564
565void as_a_strongly_typed_cpp_structure()
566{

Callers 1

mainFunction · 0.70

Calls 3

pretty_printFunction · 0.85
assume_headerMethod · 0.80
float_formatMethod · 0.45

Tested by

no test coverage detected