-
Notifications
You must be signed in to change notification settings - Fork 93
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
Add dquotes around inf
and nan
when serializing to json
#312
Comments
Indeed JSON does not encode infinity or nan. Loading rapidyaml-emitted JSON into rapidyaml will work, so currently the library is at least self-consistent. It is true that the missing quotes will make the JSON invalid according to the standard. However, if we add quotes in JSON and parse the result and emit in YAML, then these special values will be emitted with quotes, which makes them wrong in YAML, and then rapidyaml would lose the consistency there, or it would incur a significant cost while parsing by doing the string comparisons to remove the quoted flags. I don't really see a good solution here, and for now I'm inclined to leave this situation as-is. I'll leave the issue open until a better solution appears, but I'm not convinced there is one. |
If there was a way to format a float/double to a bit pattern in hexadecimal, then this could work. But I see JSON only accepts numbers as base 10... And the representation is different for a double with 32 vs 64 bits. I also don't think there is a good solution. Thinking out loud, I would propose to add an option to format these numbers per user. I don't know the implication in the code, but adding a callback (when emiting to json) for each of these case, someone could handle these like so :
You obviously loose the consistency when re importing, but the user is aware of this tarde-off. |
@biojppm I really think that the returned I would propose these changes to be done only when emiting to json :
This gives a valid json at the cost of a little inconsistency. When parsing this json back in ryml, the
I will probably go down this route, for my usecase. |
The caracters inf, -inf and nan are not valid in json. Will be converted to 8e888, -8e888 and null when emitted to json. This
The caracters inf, -inf and nan are not valid in json. Will be converted to 8e888, -8e888 and null when emitted to json. This
I think there is no way (as a number) to represent
Infinity
orNaN
in JSON. One way would be to add them as strings.Now what to do when converting to YAML... Should we keep the dquotes...
The text was updated successfully, but these errors were encountered: