Convert json numbers to numbers (#5496)

This commit is contained in:
WithoutPants
2024-11-22 08:27:23 +11:00
committed by GitHub
parent 5f690d96bd
commit 6c5bf5f052
4 changed files with 104 additions and 0 deletions

16
pkg/utils/json.go Normal file
View File

@@ -0,0 +1,16 @@
package utils
import (
"encoding/json"
"strings"
)
// JSONNumberToNumber converts a JSON number to either a float64 or int64.
func JSONNumberToNumber(n json.Number) interface{} {
if strings.Contains(string(n), ".") {
f, _ := n.Float64()
return f
}
ret, _ := n.Int64()
return ret
}