How to parse JSON in golang without unmarshaling twice

One solution is to partially unmarshal the data by unmarshalling the values into a json.RawMessage instead of an interface{}

var myMap map[string]json.RawMessage

Later in the switch, which still is required, you do not need to marshal. Just do:

err = json.Unmarshal(v, &myAck)

Playground: https://play.golang.org/p/NHd3uH5e7z

Leave a Comment