title: How do I inline fields when marshalling JSON?
body: <p>I have a type <code>MonthYear</code> defined like</p>
  
  <pre><code>type MonthYear time.Time
  
  func (my *MonthYear) MarshalJSON() ([]byte, error) {
      t := time.Time(*my)
  
      return json.Marshal(&amp;struct {
          Month int `json:"month"`
          Year  int `json:"year"`
      }{
          Month: int(t.Month()) - 1,
          Year:  t.Year(),
      })
  }
  </code></pre>
  
  <p>I'm including it a lot of different structs like</p>
  
  <pre><code>type Event struct {
      Name string `json:"name"`
      Date MonthYear
  }
  
  type Item struct {
      Category string `json:"category"`
      Date     MonthYear
  }
  </code></pre>
  
  <p>How do I inline the <code>MonthYear</code> type so that the resulting JSON does not have any embedded objects?</p>
  
  <p>I want the result to look like <code>{ "name": "party", "month": 2, "year": 2017 }</code> and <code>{ "category": "art", "month": 3, "year": 2016 }</code> without having to write the MarshalJSON for each of the structs.</p>