title: golang: "json: cannot unmarshal array into Go value of type string"
body: <p>I have a protobuf message</p>
  <pre><code>message Event {
     string type = 1;
     string names = 2;
  }
  </code></pre>
  <p>The type for ‘names’ has recently changed from <code>string</code> to <code>[]string</code> in the underlying data source where older data is still a string but new data is going to be []string.
  So, when the data is returned, some records can have string and the rest can have []string.
  I need to customize the unmarshaling (jsonpb.Unmarshaler is being used to unmarshal json.Rawmessage to Event type) and convert the ‘names’ to a string if it’s an []string (by concatenating the values from array/slice) in order to keep the response format consistent so client doesn't break.</p>
  <p>I get this error while unmarshaling:</p>
  <blockquote>
  <p>json: cannot unmarshal array into Go value of type string</p>
  </blockquote>
  <p>Can anyone please suggest on how this can be done?</p>
  <p>I tried google.protobuf.Any like below but couldn’t completely figure the unmarshaling part.</p>
  <pre><code>message Event {
     string type = 1;
     google.protobuf.Any names = 2;
  }
  </code></pre>
  <p>Unmarshall snippet:</p>
  <pre><code>evnt := new(pb.Event)
  unmarshaler    = jsonpb.Unmarshaler{AllowUnknownFields: true}
  unmarshaler.Unmarshal(bytes.NewReader(*&lt;json.RawMessage&gt;*), evnt)
  </code></pre>