Skip to content

Instantly share code, notes, and snippets.

@nikolaydubina
Created January 6, 2025 11:30
Show Gist options
  • Save nikolaydubina/e59c5d73dc678ec241a5b9b3b0616dc5 to your computer and use it in GitHub Desktop.
Save nikolaydubina/e59c5d73dc678ec241a5b9b3b0616dc5 to your computer and use it in GitHub Desktop.
// when does Go fail to encode JSON?
// https://go.dev/play/p/5ptv2ifv8_7
package main
import (
"encoding/json"
"fmt"
"math"
)
type S struct {
V float64 `json:"v"`
}
func main() {
var s S
s.V = math.Log(-1.0)
b, err := json.Marshal(s)
fmt.Print(b, err)
// [] json: unsupported value: NaN
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment