Current JSON outputs for Infinity, -Infinity, and NaN are not valid JSON. New option to allow output them as String.#164
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,-InfinityorNaN.It allows to parse them with a
+also in JavaScript.Tests included.