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
whentrue: # D20210513T172224:hereimport std/json
let a = [NaN, Inf, -Inf, 0.0, -0.0, 1e20, 1.5]
let j =%a
echo j # prints: `[nan,inf,-inf,0.0,-0.0,1e+20,1.5]`, which is invalid json (eg will fail in js console with `JSON.stringify('[nan,inf,-inf,0.0,-0.0,1e+20,1.5]')`)let j2 =$j
let j3 = j2.parseJson # errors (as it should): Error: unhandled exception: input(1, 4) Error: { expected [JsonParsingError]
Current Output
see comments
Expected Output
produce valid json
Possible Solution 1
NaN, Inf,-Inf could use newJRawNumber mechanism we added recently, but this may still lead to an ambiguity when interpreting nan for eg, as this could either mean a string nan or a number nan.
We should at least ensure roundtrip property, so that Inf => "inf" => Inf
Possible Solution 2
cast the Inf/-Inf/NaN to uint first, which would have other benefits (eg preserving bit pattern for nan so that nan value is preserved)
But this should be handled transparently for serialization/deserialization purposes
Example
Current Output
see comments
Expected Output
produce valid json
Possible Solution 1
NaN, Inf,-Inf could use
newJRawNumber
mechanism we added recently, but this may still lead to an ambiguity when interpreting nan for eg, as this could either mean a string nan or a number nan.We should at least ensure roundtrip property, so that Inf => "inf" => Inf
Possible Solution 2
cast the Inf/-Inf/NaN to
uint
first, which would have other benefits (eg preserving bit pattern for nan so that nan value is preserved)But this should be handled transparently for serialization/deserialization purposes
Additional Information
1.5.1 1e080eb
also affects jsonutils, which reuses
json.%
for this partsimilar to https://perlmaven.com/parsing-nan-in-json (see also https://stackoverflow.com/questions/6601812/sending-nan-in-json)
The text was updated successfully, but these errors were encountered: