title: How to Marshall json from one struct to another with different json tags in Go?
body: <p>I am creating a Go application that consumes data from multiple sources that all have similar data but different structures to their data/responses. These responses need to be marshalled into a common struct that is then sent to another service.</p>
  
  <p>Common struct:</p>
  
  <pre><code>type common struct {
     ID         string `json:id`
     GivenName  string `json:given_name`
     FamilyName string `json:family_name`
     Email:     string `json:email`
  }
  </code></pre>
  
  <p>One response:</p>
  
  <pre><code>{
     "id": "123",
     "first_name": "john",
     "last_name": "smith",
     "email": "js@mail.com"
  }
  
  </code></pre>
  
  <p>Another response:</p>
  
  <pre><code>{
     "id": "456",
     "first": "larry",
     "last": "smith",
     "email": {
        "primary": "larry@mail.com"
     }
  }
  </code></pre>
  
  <p>How do I marshal a json response with one structure into a struct with a different structure?</p>