-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Floating-point NaN or Infinity values should be allowed as a feature #209
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
Comments
Good idea. Would you like to implement this? |
Sure, I will work on that. |
While trying to start working, I'm wondering how to initialize a According to the general documentation: "This configuration object can be used to force the Reader or Writer to behave in a standard conforming way." But only What am I missing? |
Use neither |
I would like to get some feedback regarding the design choices: The current trunk cannot handle NaN nor infinity for Visual Studio (presumably because of an implementation defect, because the gcc code writes +/-1e+9999 for infinities and null for NaN, but reads +/-infinity and 0, respectively) and a strict reading of the JSON spec means that these values are not valid. My suggestion would be that activating a special feature flag (such as "allowSpecialFloatingPointValues") will have the effect to output NaN, Infinity, -Infinity for these three value categories and will read them back to a floating point NaN or corresponding infinity values. But what should the behaviour be, if this flag is not set? Some libraries do not accept them while writing, some do not accept them while reading or writing and in such cases an exception is thrown. Or should this flag effectively allow three states: (a) The current behaviour (default), (b) exact mapping (as described above), or (c) hard error? I would like to collect some feedback to make acceptance of the intended feature more likely. |
We're changing For the feature's name, how about Collecting feedback is a good idea! I hope you get some. |
I completely agree with the first sentence, but I don't understand how to interpret "And strict mode should follow the JSON spec", because according to http://www.ietf.org/rfc/rfc4627.txt "Numeric values that cannot be represented as sequences of digits (such as Infinity and NaN) are not permitted." My question was: How should that "not permitted" be implemented? This was the reason of my question related to exceptions. |
Strict mode will not include this new feature. In strict mode, the reader will reject any invalid symbol. Probably, it doesn't have to change at all. As for how to reject, the reader returns |
I'm still trying to figure out the architecture of the jsoncpp library to find the optimal way to implement this feature. I'm now stumbling across the http://open-source-parsers.github.io/jsoncpp-docs/doxygen/writer_8h.html Given that these free function determine in a fixed way how primitive types (such as
that would produce the alternative output requested by this issue. I need some help to understand the choices that I would have for realizing an alternative
Why are these functions part of the public API anyway? Shouldn't they actually be moved to internal headers such as to header |
I'll be awk for a couple weeks, so take your time with your new ideas... |
I'm following now all calls of |
Anyone calling That's fine. Just make it work for |
Somehow my commits have been registered under a previous issue (#214). What is the AppVeyor error "Specify which project or solution file to use because the folder contains more than one project or solution file." supposed to mean? From my point of view the implementation for #209 is completed, but I don't understand above mentioned errors |
You mentioned 209 in a comment for 214. Also, it's possible that one of your commit messages refers to 214. Not sure.
Where are you seeing that? I recently registered an AppVeyor call-back. That should eventually run CI in AppVeyor in addition to Travis, but the In the meantime, I'll try a new PR of my own to see if it triggers a similar error.
If you want, open a new PR. Or at least, rebase to the tip of |
If you visit #217 and go down to the bottom of the page immediately after my last comment starting with "I was quite busy ..." you should see my very last commits. The last six of them are marked red and I don't understand the reason for this. Clicking on the details of the problem I'm referred to this page: https://ci.appveyor.com/project/cdunn2001/jsoncpp/build/1.0.4 I don't understand the problems mentioned there. Locally - compiled against gcc mingw and Visual Studio I don't get any compile errors (but I see some cmake related errors which are not mine, since I have not touched any cmake files). What do I need to do so make the last commits of mine available to you? |
…pen-source-parsers#209 Introduce 'allowSpecialFloats' for readers and 'useSpecialFloats' for writers, use consistent macro snprintf definition for writers and readers, provide new unit tests for open-source-parsers#209
…pen-source-parsers#209 Introduce 'allowSpecialFloats' for readers and 'useSpecialFloats' for writers, use consistent macro snprintf definition for writers and readers, provide new unit tests for open-source-parsers#209
After a lengthy period being absent from this project I restarted and reset my fork to the head of the upstream project and retried with a new suggestion. Essentially the implementation should be equal compared to my previous suggestion except that I no longer suggest a separate new (internal) header. Nonetheless I ensured that the two non-equivalent handling of I hope my new start is now more readable in regard to git history line. |
Shouldn't this issue be closed now? |
Yes, and thanks for your help. |
The JSON specification doesn't support special floating values such as any NaN value or +/-infinity. But many (if not most) Json libraries at least provide a special Flag to allow them. As an example see the flag serializeSpecialFloatingPointValues of the google-Gson library:
http://google-gson.googlecode.com/svn-history/trunk/gson/docs/javadocs/com/google/gson/GsonBuilder.html#serializeSpecialFloatingPointValues%28%29
It seems that the choice of representation chosen here (
NaN
for a NaN,Infinity
and-Infinity
for positive/negative infinity is quite popular and I recommend to use them when this feature is active.Other JSON library with similar support:
https://github.com/aseemk/json5
https://simplejson.readthedocs.org/en/latest/
The text was updated successfully, but these errors were encountered: