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

yajl_gen_double uses a comma instead of a point #222

Open
PaulCombal opened this issue Nov 9, 2019 · 4 comments
Open

yajl_gen_double uses a comma instead of a point #222

PaulCombal opened this issue Nov 9, 2019 · 4 comments

Comments

@PaulCombal
Copy link

PaulCombal commented Nov 9, 2019

All is in the title.
Here is sample code:

    yajl_gen_string_wrap(handle, RATE_STR);
    if (yajl_gen_double(handle, (double)achievement.global_achieved_rate) != yajl_gen_status_ok) {
            std::cerr << "failed to make json" << std::endl;
    }

Here is the output:

... "RATE":86,500000,"ICON":242 ...

So as you can see, this produces invalid JSON since the comma cannot be used here as a delimiter.

Is it normal, how can I solve this?

Thanks

Edit: my version: 2.1.0-2, my OS language setting is French if this can help, if it has to do with formatting from the os or anything

@drjasonharrison-vp-eio
Copy link

Looks like a localization issue. French using the comma where json would expect a dot.

@PaulCombal
Copy link
Author

PaulCombal commented Nov 9, 2019

Indeed, with further testing I figured everything works like a charm using LC_NUMERIC=en_US.UTF-8 before launching my app. I don't think this is a feature. Will this be fixed by any chance? JSON is the same whatever the laguage.

@drjasonharrison-vp-eio
Copy link

Two options for fixing this on yajl side come to mind. The first is to call setlocale(LC_NUMERIC, "C") before the sprintf and use the returned value from setlocale to reset after the sprintf. This can also be done in the calling code of yajl.

The second option is for yajl to call localeconv and use the value of the returned struct lconv field decimal_point to determine if the locale should be changed, or if the decimal point in the output of the sprintf should have the decimal point be changed.

Since C locale is global to a program, it might be even better to avoid locale at all and check for comma in the output of sprintf in yajl_gen_double and replace it with a dot. This will have a negative performance impact.

@5HT2
Copy link

5HT2 commented Mar 12, 2022

Any updates on this?

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

3 participants