title: What's the proper way to convert a json.RawMessage to a struct?
body: <p>I have this <code>struct</code></p>
  
  <pre><code>type SyncInfo struct {
      Target string
  }
  </code></pre>
  
  <p>Now I query some <code>json</code> data from ElasticSearch. <code>Source</code> is of type <code>json.RawMessage</code>.
  All I want is to map <code>source</code> to my <code>SyncInfo</code> which I created the variable <code>mySyncInfo</code> for.</p>
  
  <p>I even figured out how to do that...but it seems weird. I first call <code>MarshalJSON()</code> to get a <code>[]byte</code> and then feed that to <code>json.Unmarshal()</code> which takes an <code>[]byte</code> and a pointer to my struct. </p>
  
  <p>This works fine but it feels as if I'm doing an extra hop. Am I missing something or is that the intended way to get from a <code>json.RawMessage</code> to a <code>struct</code>?</p>
  
  <pre><code>var mySyncInfo SyncInfo
  
  jsonStr, _ := out.Hits.Hits[0].Source.MarshalJSON()
  json.Unmarshal(jsonStr, &amp;mySyncInfo)
  
  fmt.Print(mySyncInfo.Target)
  </code></pre>