title: How to not marshal an empty struct into JSON with Go?
body: <p>I have a struct like this:</p>
  
  <pre><code>type Result struct {
      Data       MyStruct  `json:"data,omitempty"`
      Status     string    `json:"status,omitempty"`
      Reason     string    `json:"reason,omitempty"`
  }
  </code></pre>
  
  <p>But even if the instance of MyStruct is entirely empty (meaning, all values are default), it's being serialized as:</p>
  
  <pre><code>"data":{}
  </code></pre>
  
  <p>I know that the <a href="http://golang.org/pkg/encoding/json/#Marshal" rel="noreferrer">encoding/json</a> docs specify that "empty" fields are:</p>
  
  <blockquote>
    <p>false, 0, any nil pointer or interface value, and any array,
    slice, map, or string of length zero</p>
  </blockquote>
  
  <p>but with no consideration for a struct with all empty/default values. All of its fields are also tagged with <code>omitempty</code>, but this has no effect.</p>
  
  <p>How can I get the JSON package to <em>not</em> marshal my field that is an empty struct?</p>