Skip to content
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

Boost.JSON output for numbers with scientific format is incorrect #156

Open
sicheste opened this issue Oct 28, 2022 · 8 comments
Open

Boost.JSON output for numbers with scientific format is incorrect #156

sicheste opened this issue Oct 28, 2022 · 8 comments

Comments

@sicheste
Copy link
Contributor

sicheste commented Oct 28, 2022

When enabling in main.cpp lines 1139 and 1140 it is showing the differences in parsing. For the Boost.JSON it will for example print this:

Expect: [5e-324]
Actual: [5E-324]

Intput from roundtrip24.json is simply [5e-324].

Somewhere the formatting is broken. By default Boost.JSON would output e instead of E:

#include <boost/json/src.hpp>
#include <iostream>
#include <string>

int main(int, char**) {
  std::string json("[5e-342]");
  std::string result = boost::json::serialize(json);
  std::cout << "input: " << json << "\nresult: " << result << std::endl;
  return 0;
}

Output:

input: [5e-342]
result: "[5e-342]"

The exponent e is lower case here. I did not had enough time to search for some formatting settings in the application.

@niXman
Copy link

niXman commented Jan 23, 2023

@sicheste

Expect: [5e-324]
Actual: [5E-324]

is there any reason except aesthetic?

and why you are posting it here instead of the boost.json developer project?

@sicheste
Copy link
Contributor Author

is there any reason except aesthetic?

Yes, the test application is treating this as an invalid result. It is not making a string to lower or similar before comparing the result to the expected value.

and why you are posting it here instead of the boost.json developer project?

Because this formatting is set somewhere within the test application. As you can se in my minimal example from above, it is not caused by Boost.JSON. Maybe it is set by another JSON library. I do not know why, I have not digged deeper. But it is not the default behaviour of Boost.JSON.

@niXman
Copy link

niXman commented Jan 26, 2023

When enabling in main.cpp

where is that file?

@sicheste
Copy link
Contributor Author

When enabling in main.cpp

where is that file?

https://github.com/miloyip/nativejson-benchmark/blob/master/src/main.cpp#L1139

@niXman
Copy link

niXman commented Jan 26, 2023

but according to the JSON grammar: https://www.json.org/json-en.html, the exponent char may be one of e or E. so from a formal point of view everything is correct here.

@sicheste
Copy link
Contributor Author

But then this means that the comparision within the benchmark application is incorrect. So Boost.JSON is blamed to be not be fully following the standard by mistake.

I am totally fine to rephrase the title of this issue. But currently Boost.JSON is giving a result which seems correct, the test application does not accept it as being correct. When, regarding to the JSON specificition, it is fine to use e or E, then both should be accepted.

@niXman
Copy link

niXman commented Jan 26, 2023

first - according to the doc it seems your example uses boost::json::serialize(string) which call for serialize_impl(), reset(string *) and finally uses write_string() which do nothing with doubles except for escaping the string.

second - try to change your code that it parse the string first and serialize it back as string. and then show the result.

@niXman
Copy link

niXman commented Jan 26, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants