Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang decode map[string]float where float is encoded as string

Tags:

json

go

So I'm dealing with an api that provides a json object that maps a string to a float, however, they encode the float as a string.

I know that you can use tags in the struct to say when an individual float is encoded as a string:

Item float64 `json:",string"`

I'm not necessarily against the idea of using an interface{} as the value in the map, but it just strikes me that there should be a way to do it.

Playground of example: http://play.golang.org/p/972hLoXbek

like image 532
Snapbug Avatar asked Oct 21 '22 14:10

Snapbug


1 Answers

How about using json.Number? Example: http://play.golang.org/p/JiAA1HORuV No idea if its the best way to do it though...

like image 104
Milan Halada Avatar answered Oct 24 '22 11:10

Milan Halada