title: Golang unmarshaling JSON to protobuf generated structs
body: <p>I would like to reqeive a JSON response withing a client application and unmarshal this response into a struct. To ensure that the struct stays the same accross all client apps using this package, I would like to define the JSON responses as protobuf messages. I am having difficulties unmarshaling the JSON to the protobuf generated structs.</p>
  <p>I have the following JSON data:</p>
  <pre><code>[
    {
      &quot;name&quot;: &quot;C1&quot;,
      &quot;type&quot;: &quot;docker&quot;
    },
    {
      &quot;name&quot;: &quot;C2&quot;,
      &quot;type&quot;: &quot;docker&quot;
    }
  ]
  </code></pre>
  <p>I have modeled my protobuf definitions like this:</p>
  <pre><code>syntax = &quot;proto3&quot;;
  package main;
  
  message Container {
      string name = 1;
      string type = 2;
  }
  
  message Containers {
      repeated Container containers = 1;
  }
  </code></pre>
  <p>Using this pattern with structs normaly works, but for some reason using these proto definitions causes issues. The below code demonstrates a working and a non-working example. Although one of the versions work, I am unable to use this solution, since <code>[]*Container</code> does not satisfy the <code>proto.Message</code> interface.</p>
  <pre><code>package main
  
  import (
      &quot;encoding/json&quot;
      &quot;fmt&quot;
      &quot;strings&quot;
  
      &quot;github.com/gogo/protobuf/jsonpb&quot;
  )
  
  func working(data string) ([]*Container, error) {
      var cs []*Container
      return cs, json.Unmarshal([]byte(data), &amp;cs)
  }
  
  func notWorking(data string) (*Containers, error) {
      c := &amp;Containers{}
      jsm := jsonpb.Unmarshaler{}
      if err := jsm.Unmarshal(strings.NewReader(data), c); err != nil {
          return nil, err
      }
      return c, nil
  }
  
  func main() {
      data := `
  [
    {
      &quot;name&quot;: &quot;C1&quot;,
      &quot;type&quot;: &quot;docker&quot;
    },
    {
      &quot;name&quot;: &quot;C2&quot;,
      &quot;type&quot;: &quot;docker&quot;
    }
  ]`
  
      w, err := working(data)
      if err != nil {
          panic(err)
      }
      fmt.Print(w)
  
      nw, err := notWorking(data)
      if err != nil {
          panic(err)
      }
      fmt.Print(nw.Containers)
  }
  </code></pre>
  <p>Running this gives the following output:</p>
  <pre><code>[name:&quot;C1&quot; type:&quot;docker&quot;  name:&quot;C2&quot; type:&quot;docker&quot; ]
  panic: json: cannot unmarshal array into Go value of type map[string]json.RawMessage
  
  goroutine 1 [running]:
  main.main()
          /Users/example/go/src/github.com/example/example/main.go:46 +0x1ee
  
  Process finished with exit code 2
  </code></pre>
  <p>Is there a way to unmarshal this JSON to <code>Containers</code>? Or alternatively, make <code>[]*Container</code> to satisfy the <code>proto.Message</code> interface?</p>