title: How to ignore JSON fields when marshalling not unmarshalling
body: <p>Assume I have a password field in a User struct.</p>
  
  <pre><code>type User struct{
     UserName string `json:"username"`
     Password string `json:"-"`
  }
  </code></pre>
  
  <p>My clients register their users by posting username and password together. So if I decode JSON to above struct, it ignores password. It's expected. But I wondered is there any way to ignore fields when only marshalling. I checked go official documentation page but couldn't find anything. </p>
  
  <p><a href="https://golang.org/pkg/encoding/json/" rel="noreferrer">https://golang.org/pkg/encoding/json/</a></p>
  
  <p>I can add an extra field into the struct but I need to know first is it possible to do that with JSON lib.</p>