Snapbug
Snapbug

Reputation: 73

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

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

Upvotes: 5

Views: 1365

Answers (1)

Milan Halada
Milan Halada

Reputation: 1934

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

Upvotes: 3

Related Questions