-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Serializing NaN results in non-JSON compliant text #1
Comments
Write a JsonConverter for float/double to make NaN safe if this is important for you. |
The problem is that NaN (and infinity) values in float/double are not valid JSON values. Deserializing the JSON from any other application will simply not work... can we reopen this issue? |
+1 @JamesNK: Shouldn't Newtonsoft.Json try to be fully compatible to http://tools.ietf.org/html/rfc4627 as defined by D. Crockford which means no "NaN" or "Infinite"? "Write a JsonConverter for float/double to make NaN safe if this is important for you." |
+1 NaN-values really should comply with the rfc. |
+1 when a json serializer outputs invalid json - definitely a bug |
For posterity, here's a very simple example of a JsonConverter for doubles that JamesNK was referring to: https://gist.github.com/collinsauve/6122751 |
This issue was addressed a couple of months ago - http://james.newtonking.com/archive/2013/04/07/json-net-5-0-release-1-net-4-5-biginteger-read-only-collections.aspx |
Bug: unexpected token: Comment test case updated
When serializing numeric properties of classes that, for example, divide by zero, the result is NaN, breaking the JSON output.
{ "InvalidCalculatedProperty" : NaN }
I'd recommend switching to string type in this case:
{ "InvalidCalculatedProperty" : "NaN" }
...or, perhaps, throwing an exception.
Anything else, but the current output isn't valid.
Thank you for this amazing library. Keep up the great work. Cheers! -Jonathan
The text was updated successfully, but these errors were encountered: