I want to convert bson in mongo-go-driver to json effectively.
I should take care to handle NaN
, because json.Marshal
fail if NaN
exists in data.
For instance, I want to convert below bson data to json.
b, _ := bson.Marshal(bson.M{"a": []interface{}{math.NaN(), 0, 1}})
// How to convert b to json?
The below fails.
// decode
var decodedBson bson.M
bson.Unmarshal(b, &decodedBson)
_, err := json.Marshal(decodedBson)
if err != nil {
panic(err) // it will be invoked
// panic: json: unsupported value: NaN
}