Closed pedromss closed 4 years ago
By default Golang set JSON number to float64
, if you need to get the integer value then you can use the Result.As()
method
const json = `{"name":{"first":"Tom","last":"Hanks"},"age":61}`
result, _ := gojsonq.New().JSONString(json).FindR("age") // handle error
var age int
result.As(&age) // handle error
fmt.Printf("%#v\n", age)
From the example on the readme:
Why does
age
get set as afloat64
instead of anint
orint64
? Not very intuitive because looking at the JSON there are no decimal places and the number is small. What's the rationale? Is it alwaysfloat64
?