-
Notifications
You must be signed in to change notification settings - Fork 87
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
NaN is serialized to NaN should be "null" #395
Comments
I'm not sure what you are proposing. NaN and +/- Infinity cannot be represented in JSON. The quote above is from the Javascript spec which isn't the same thing. My preference would be to parse NaN, +Infinity, -Infinity as the corresponding floating point values, perhaps using some trickery with |
An option for signaling NaN would be nice, FWIW. |
Hi Jacob, I'm sorry for the confusion. If I do something like this type(json_core) :: json
type(json_value), pointer :: root
zero = 0
nan = 0/zero
call json%add(root, 'nan', nan)
call json%print(root, './nan.json')
call json%destroy(root) I would get I guess what I'm proposing is to serialize NaN and Infinity into "null" in the output. Let me know if this cleared things up a bit. |
I guess we could have different options. Keep in mind that it also has to work for parsing. Would it be better to represent it as the JSON
The problem with the first two is that they aren't reversible. You can add a +Infinity but you can't get it back. The last one is reversable. This could be important if using an array. For example: it seems weird to produce something like this:
|
I feel this is inherently difficult, given the JSON spec, in a perfect world JSON would adhere to ieee floating points, it bit me in the foot, when I found out that JSON did not support ieee. I'm using your lib in my blas project, but given all these issues, I might just do the serializing from fortran to rust myself, then using JSON as format in between. I like your idea to have an optional JSON5 parser, but maybe even just documenting that we don't follow spec when it comes to NaN and Infinities is sufficient. |
… -Infinity real values. If these value are encountered, they are serialized as strings (in quotes). See #395
Note: see the new |
Following the JSON spec NaN and +/- infinity should be serialized to "null"
https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript
The text was updated successfully, but these errors were encountered: