-
Notifications
You must be signed in to change notification settings - Fork 335
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
Current JSON outputs for Infinity, -Infinity, and NaN are not valid JSON. New option to allow output them as String. #164
base: master
Are you sure you want to change the base?
Conversation
…SON String values in case of Infinity, -Infinity or NaN
Can we have some discussion on this topic? Has this pull request some options of being merged? |
It's unlikely to get merged, just because simplejson already has too many options, and this has never been requested before. I do otherwise think it is a nice approach to the problem. |
Thanks for your explanation. Two of the five open pull requests are about serializing valid standard JSON. I think that following the standard definition was a requirement, anyway. Thanks you a lot again for your great work on the library. Perhaps we will fork it to add this option, but the library is pretty good. Regards, |
Just for the record, I published the fork as |
If you're going to do that, I would probably recommend that the default be to throw an exception ( > JSON.stringify([+'Infinity', +'NaN'])
"[null,null]" |
Yes, outputting |
Sure, I'm just recommending a default that rejects them or does what JavaScript does. |
Hi @robermorales, Thanks for creating this issue and the fork! I had the same problem - I'm serializing a complex nested data structure with possible nan/infs, and it's difficult to replace all nan/infs manually before serializing. I was able to get away with simplejson's |
I added a big_floats_as_string boolean option to allow producing valid JSON String values in case of
Infinity
,-Infinity
orNaN
.It allows to parse them with a
+
also in JavaScript.Tests included.