From e1b2d61ceba2958aaf91a128f6a9cd5d3a3b41f1 Mon Sep 17 00:00:00 2001 From: Kyle Brandt Date: Tue, 6 Aug 2019 12:28:48 -0400 Subject: [PATCH] backend: null.Float NaN -> null for json marshal (#18284) --- pkg/components/null/float.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/components/null/float.go b/pkg/components/null/float.go index 24e7ca4337e..5a5d2af236f 100644 --- a/pkg/components/null/float.go +++ b/pkg/components/null/float.go @@ -4,6 +4,7 @@ import ( "database/sql" "encoding/json" "fmt" + "math" "reflect" "strconv" ) @@ -99,7 +100,7 @@ func (f *Float) UnmarshalText(text []byte) error { // MarshalJSON implements json.Marshaler. // It will encode null if this Float is null. func (f Float) MarshalJSON() ([]byte, error) { - if !f.Valid { + if !f.Valid || math.IsNaN(f.Float64) { return []byte(nullString), nil } return []byte(strconv.FormatFloat(f.Float64, 'f', -1, 64)), nil