Closed alexgarzao closed 3 years ago
This is expected per Go's JSON marshaller. https://pkg.go.dev/encoding/json#Decoder.UseNumber
I'd suggest to use a strongly typed struct for your data (instead of map[string]interface{}
), where the unmarshaller would know what type of the field you actually expect.
But, the safest option is to render all IDs as strings in the JSON payload, since JSON (JavaScript) can't handle big integers. We ran into some problems with int64
IDs loosing precision in the JavaScript application, cause JavaScript's float couldn't handle it. The safest solution was to switch to strings (for IDs) everywhere.
type MyPayload struct{
ID int64 `json:"id,string"`
}
Hello.
I'm trying to get data from claims, after the decode. But it seems that the original value (an int) turns a float64, after the decode.
Example:
When I run this, I got "userID 123 is float".
I'm using go 1.16.6, on ubuntu 21.04.
I am doing something wrong?
Thanks