I'm working with an API that usually provides json string values but they will sometimes provide numbers instead. For example, 99% of the time it's like this:
{
"Description": "Doorknob",
"Amount": "3.25"
}
But for whatever reason, sometimes it's like this:
{
"Description": "Lightbulb",
"Amount": 4.70
}
Here is the struct I'm using which works in 99% of the time:
type Cart struct {
Description string `json:"Description"`
Amount string `json:"Amount"`
}
But it'll break when they provide a numeric amount. What's the best way to type check when unmarshaling a struct?
playground: https://play.golang.org/p/S_gp2sQC5-A