title: Ignore unsupported type error on JSON Marshal
body: <p>Here is my code:</p>
  <pre><code>func dump(w io.Writer, val interface{}) error {
      je := json.NewEncoder(w)
      return je.Encode(val)   
  }
  
  type example struct {
      Name string
      Func func() 
  }
  
  func main() {
      a := example{
          Name: &quot;Gopher&quot;,
          Func: func() {},
      }
      err := dump(os.Stdout, a)
      if err != nil {
          panic(err)
      }
  }
  </code></pre>
  <p>The program will panic with <code>json: unsupported type: func()</code></p>
  <p>My question is, how can I encode ANYTHING into json, ignoring those the encode cannot handle. For example, the above data structure, I want the output to be: <code>{&quot;Name&quot;: &quot;Gopher&quot;}</code></p>
  <p>IMPORTANT: for the dump funtion, its value is an <code>interface{}</code>, i.e. don't know what kind of data it will receive, so tricks like <code>json:&quot;-&quot;</code> is <strong>not</strong> what I want.</p>
  <p>If in case that the data passed to dump() is not marshal-able, e.g. <code>dump(func(){})</code>, it is perfectly acceptable to just return empty string.</p>
  <p><strong>EDIT after two years:</strong></p>
  <p>The answer provided by @TehSphinX has this piece of code which I want to avoid:</p>
  <pre><code>func (s example) MarshalJSON() ([]byte, error) {
      return json.Marshal(struct {
          Name string
      }{
          Name: s.Name,
      })
  }
  </code></pre>
  <p>the reason is: in <code>func dump(w io.Writer, val interface{}) error</code>, the <strong><code>val</code></strong> is ANY code, i.e. code NOT written by me, could be any open source code, or even data types I don't have access to its source code.</p>