You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FSharp.Data serializes NaN as just NaN, Infinity as just Infinity and -Infinity as -Infinity.
If I understand it correctly, there is no JSON representation for these values, so emitted JSON is not valid.
Repro script:
openFSharp.DataletserializeDeserializeFloat floatValue =letjsonValue= JsonValue.Array ([| JsonValue.Float floatValue |])letjson= jsonValue.ToString(JsonSaveOptions.DisableFormatting)
printfn "Serialized: %A" json
letjsonValue= JsonValue.Parse json
printfn "Deserialized: %A" jsonValue
serializeDeserializeFloat 42.0// OK
serializeDeserializeFloat nan
// Throws exception// System.Exception: Invalid JSON starting at character 1, snippet = // ----// [NaN]// -----// json = // ------// [NaN]// -------
serializeDeserializeFloat infinity
//System.Exception: Invalid JSON starting at character 1, snippet = //----//[Infinity]//-----//json = //------//[Infinity]//-------
serializeDeserializeFloat -infinity
//System.Exception: Invalid JSON starting at character 2, snippet = //----//[-Infinity]//-----//json = //------//[-Infinity]//-------
For example, Firefox console encodes these values like this:
For example Newtonsoft.Json serializes these values as strings. NaN is "NaN", Infinity is "Infinity" and -Infinity is "-Infinity", so it is able to deserialize it back to float and JSON is valid.
FSharp.Data serializes NaN as just
NaN
, Infinity as justInfinity
and -Infinity as-Infinity
.If I understand it correctly, there is no JSON representation for these values, so emitted JSON is not valid.
Repro script:
For example, Firefox console encodes these values like this:
The text was updated successfully, but these errors were encountered: