5

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

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

It'll do, at least more consistent than using strconv I feel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.