Standard library / encoding/json

encoding/json.Decoder.UseNumber()

Decode numbers stored in interface values as json.Number instead of float64. Choose a numeric conversion explicitly to avoid accidental precision loss. Expected stdout: 'json.Number 9007199254740993\n'.

Formal Syntax & Structure

go syntaxgo
func (dec *Decoder) UseNumber()

Working Example

Example Snippetgo
package main
import (  "encoding/json"  "fmt"  "strings")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  d := json.NewDecoder(strings.NewReader("9007199254740993"))  d.UseNumber()  var x any  must(d.Decode(&x))  fmt.Printf("%T %v\n", x, x)}
Go Reference