title: Converting struct with embedded interface into JSON
body: <p>I have a struct that I want to marshal to JSON. It has a defined field called <code>Foo</code> (exported as <code>foo</code>) and a <code>data</code> interface field to which I want to pass a dynamic struct with additional JSON fields.</p>
  
  <p>However when the data field is an interface instead of the specific struct it never gets exported as JSON. How can I make this work?</p>
  
  <pre><code>package main
  
  import (
      "encoding/json"
      "fmt"
  )
  
  type data interface{}
  
  type foo struct {
      Foo string `json:"foo,omitempty"`
      data
  }
  
  type bar struct {
      Bar string `json:"bar,omitempty"`
  }
  
  func main() {
      b := bar{"bar"}
      f := foo{"foo", b}
  
      byt, err := json.Marshal(f)
      if err != nil {
          fmt.Println(err)
          return
      }
      fmt.Println(string(byt))
  }
  </code></pre>
  
  <p>I need to output to look like this (it needs to be flat, not nested):</p>
  
  <pre><code>{"foo": "foo", "bar": "bar"}
  </code></pre>