inf := math.Inf(1)
json.Marshal(inf)
json.Marshal(struct{ F float64 }{inf})
json.Marshal(map[string]any{"k": inf})
v1 returns "json: unsupported value: +Inf" in all three cases.
v2 (including v1 with GOEXPERIMENT=jsonv2) returns "json: unsupported value: +Inf" in the first two cases, but succeeds and returns {"k":"Infinity"}
in the third case.
Seems like an unintentional change? I'd expect all three cases to succeed or fail.
Comment From: neild
/cc @dsnet
Comment From: gabyhelp
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: dsnet
This works correctly if you set the optimizeCommon
constant to false, which indicates that the optimized implementation is wrong.
Comment From: gopherbot
Change https://go.dev/cl/695276 mentions this issue: encoding/json/v2: fix incorrect marshaling of NaN in float64 any