Standard library / encoding/json

encoding/json.Number.Int64()

Parse the original number as a signed base-ten int64. Fractions, exponent notation and out-of-range values return errors. Expected stdout: '42 true\n'.

Formal Syntax & Structure

go syntaxgo
func (n Number) Int64() (int64, error)

Return Value

(int64, error)

Parsed integer and conversion error.

Working Example

Example Snippetgo
package main
import (  "encoding/json"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  x, e := json.Number("42").Int64()  must(e)  _, bad := json.Number("1.5").Int64()  fmt.Println(x, bad != nil)}
Go Reference