I need to parse json into a struct in golang and the final value is a float64
But it seems that some inputs encode it as a string and some encode it as a float64
This is across a lot of variables so I would rather not make a custom function for each field
What is the best way to do this in golang?
I know the json tags can let values be stored as strings, but now that I am receiving raw floats it is starting to error out
This is a parsing FROM json only operation, so I do not care about what it implies or makes impossible for encoding TO json
Example code:
type Example struct {
var1 float64 `json:"var1"`
}
func main() {
var ex Example
json.Unmarshal([]byte("{"var1":10.0}", &ex)
json.Unmarshal([]byte("{"var1":"10.0"}", &ex)
}