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

json.d Browser compatibility: Don't output nan for floating point values. #1323

Closed
wants to merge 1 commit into from
Closed

Conversation

rjmcguire
Copy link

Can't output nan in JSON documents. Browsers don't support it. {"float":nan} is not valid JSON for example.

Can't output nan in JSON documents. Browsers don't support it. {"float":nan} is not valid JSON for example.
@s-ludwig
Copy link
Member

I think we should go with the same strategy as std_data_json and ouput null instead. This of course requires that the deserializer is also adjusted and converts null to NaN. Converting to 0 on the other hand looks like it would inadvertently hide potential bugs.

@rjmcguire
Copy link
Author

What would it be used for (other than internally as a novelty format) if
it can't be used with web browsers?

On Tue, Nov 10, 2015 at 12:18 PM, Sönke Ludwig notifications@github.com
wrote:

I think we should go with the same strategy as std_data_json
https://github.com/s-ludwig/std_data_json/blob/master/source/stdx/data/json/generator.d#L450
and ouput null instead. This of course requires that the deserializer is
also adjusted and converts null to NaN. Converting to 0 on the other hand
looks like it would inadvertently hide potential bugs.


Reply to this email directly or view it on GitHub
#1323 (comment)
.

@s-ludwig
Copy link
Member

What would it be used for (other than internally as a novelty format) if
it can't be used with web browsers?

I was suggesting to output null instead of 0, which is also valid JSON. If you mean those special NaN and Infinity literals in the std_data_json code, please don't ask me, ask those that have requested it ;) (but it's a compile-time option, so no harm done by default)

@rjmcguire
Copy link
Author

Explains why the Chrome browsers json parser's error is "unexpected 'a' "
when it finds nan.

Should I just delete my PR or should I change it? There is at least one
unittest that checks nan serialization but it doesn't seem to test the code
I changed.

On Tue, Nov 10, 2015 at 1:15 PM, Sönke Ludwig notifications@github.com
wrote:

What would it be used for (other than internally as a novelty format) if
it can't be used with web browsers?

I was suggesting to output null instead of 0, which is also valid JSON.
If you mean those special NaN and Infinity literals in the std_data_json
code, please don't ask me, ask those that have requested it ;) (but it's a
compile-time option, so no harm done by default)


Reply to this email directly or view it on GitHub
#1323 (comment)
.

@s-ludwig
Copy link
Member

Got fixed by #1548.

@s-ludwig s-ludwig closed this Aug 11, 2017
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

Successfully merging this pull request may close these issues.

None yet

2 participants