-
Notifications
You must be signed in to change notification settings - Fork 616
JSON output is locale-dependent and is not cross-platform. #38
Comments
Sergey Thanks for pointing that out. I'm just a user myself, not any of the Peter On Wed, Jul 29, 2015 at 6:26 AM, sergey-shambir [email protected]
|
It does: http://www.json.org/ It is very clear that a period is supposed to be used for the decimal point if you look at the parsing diagrams. |
This is definitely a bug. We likely don't have time to implement a proper fix, but I'd love to see a pull request. Options include:
|
|
What about import code from and the code is under MIT license? |
Also there is https://github.com/google/double-conversion from author of |
I convert json11 to usage of double-conversion (for string->double and double->string): Dushistov@115fc76 nativejson-benchmark from here Before: After: As you can see speedup 24% for parsing, and 374% for dump, What do you think? |
I like the idea of fixing this, and like the sound of those benchmarks. A submodule seems quite heavy weight for json11, which is currently a very tiny library which is easy to integrate. Dropbox's own build environment wouldn't have any trouble with a submodule, but it's a lot of overhead for other users. Is there a simpler option? I'll get an answer on whether the license is okay, but I suspect it would be. |
Bump. In my opinion this is a pretty heavy bug. I'm happy I found this discussion after googleing the right words. |
Pull requests welcome. |
@j4cbo suggested the followings:
Are all good for you? Probably point 2 would be a quick (though pretty dirty) solution while waiting for someone to implement or port grisu2. |
I don't have time to go deep, but they all sound plausible. My primary concerns on any new dependencies would be how portable they are, particularly to the mobile platforms where Dropbox uses json11. For something hand-tweaked like #2 I'd just want to make sure it has minimal risk for unintended impact (i.e. don't accidentally mess with commas in strings) and minimal performance impact. |
Patch for json.cpp
To reproduce this in tests, locale is need to be set at the start of testcase (commented out in patch). Patch for test.cpp
I think it's in the spirit of json11, but whatever, hope this helps. |
Thanks for taking a stab at it. Please phrase your submissions in the form of a Pull Request, though, not a patch. On a quick look, I wonder about the potential performance difference between stringstream and snprintf, and whether that could add up when printing a lot of numbers. I wouldn't know for sure if that's an issue without measuring, though. |
C++17 has std::from_chars() and std::to_chars() specifically for this kind of usage (JSON, etc...). They're also supposed to be very fast (faster than the usual locale-aware functions). http://en.cppreference.com/w/cpp/utility/from_chars |
Nah, i'm good. I can only note that it's too trivial to be copyrighted, so anyone are welcome to do whatever they want with those patches. |
Parse the number according to the JSON grammar, ignoring the current locale.
json11 uses locale-dependent functions for conversion between double and it's string representation. On Ubuntu with Russian language it prints doubles with comma like '3,1415926'. On Windows with Russian language pack or any OS with English language it prints '3.1415926' and parser also expects '3.1415926' so '3,1415926' cannot be parsed.
The text was updated successfully, but these errors were encountered: