Skip to content

Commit

Permalink
csv_options column_mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Jan 20, 2025
1 parent 997092a commit be31af3
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/csv/src/csv_encoder_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,61 @@ TEST_CASE("test json to flat csv with column mappings")

CHECK(expected == buf);
}

SECTION("array of arrays to csv")
{
std::string expected = R"(Date Time,Newspaper
1971-01-01T04:14:00,Chicago Reader
1948-01-01T14:57:13,Chicago Sun-Times
)";

std::string jtext = R"(
[
[
"Chicago Reader",
1.0,
"1971-01-01T04:14:00",
true,
[
"04:14:00",
[
"1971-01-01",
40
]
]
],
[
"Chicago Sun-Times",
1.27,
"1948-01-01T14:57:13",
true,
[
"14:57:13",
[
"1948-01-01",
63
]
]
]
]
)";

auto j = jsoncons::json::parse(jtext);
//std::cout << pretty_print(j) << "\n";

auto options = csv::csv_options{}
.flat(true)
.column_mapping({
{"/2","Date Time"},
{"/0","Newspaper"}
});

std::string buf;
csv::csv_string_encoder encoder(buf, options);
j.dump(encoder);

CHECK(expected == buf);
}
}

TEST_CASE("test json to flat csv")
Expand Down

0 comments on commit be31af3

Please sign in to comment.