-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
csv reader: too big number causing a parse error when infer_types is on #333
Comments
This
isn't right, should be
I'm assuming that's a typo, though. Your example should work. This test on Windows 10 produces the same results with both VS and clang: #include <jsoncons/json.hpp>
#include <jsoncons_ext/csv/csv.hpp>
using jsoncons::json;
int main()
{
std::string data = R"(Drive,DeviceName,State,Temp(C),LoopState,LoopState
0:0,5000C50093B7DF54,Normal,29,OK,OK
8:0,5001173100E7BDFC,Normal,33,OK,OK
)";
jsoncons::csv::csv_options options;
options.assume_header(true);
options.field_delimiter(',');
try
{
const auto csv = jsoncons::csv::decode_csv<jsoncons::json>(data, options);
std::cout << pretty_print(csv) << "\n";
}
catch (const std::exception& e)
{
std::cout << e.what() << "\n";
}
} Output:
|
oh yes, that was a copy&paste. I checked again and found out I was accidently on 0.157.1 Perhaps I stripped down the data too much
I now get:
on the old version, it broke at line 10 column 21.
|
Okay, it's failing on line 11, with this one
It infers that's a number. I think this is a situation where you have to specify the column types explicitly. There's still a defect, the parser recognized 5001173100E95978 as a JSON number, but tried to convert it into an integer rather than a float, because there was no decimal point. But with the E, it should have gone with the float. We'll fix that in the next release. If it's more convenient, you can just specify the first two types, it'll infer the rest:
Output:
|
I'm parsing a CSV file
with
It throws me a parse error exception with line/column information pointing to the comma after "FC" (last line from CSV)
it seems it tries to interpret the number 5001173100E7BDFC as scientific notation: 5001173100 E 7BDFC and of course can't fit it into one.
Shouldn't it fall back to "string" if it can't infer a numerical type?
The parse error is really unexpected there and took us a while to figure out whats wrong.
What compiler, architecture, and operating system?
What jsoncons library version?
The text was updated successfully, but these errors were encountered: