title: How to convert bson to json effectively with mongo-go-driver?
body: <p>I want to convert bson in <a href="https://github.com/mongodb/mongo-go-driver" rel="nofollow noreferrer">mongo-go-driver</a> to json effectively.</p>
  
  <p>I should take care to handle <code>NaN</code>, because <code>json.Marshal</code> fail if <code>NaN</code> exists in data.</p>
  
  <p>For instance, I want to convert below bson data to json.</p>
  
  <pre class="lang-golang prettyprint-override"><code>b, _ := bson.Marshal(bson.M{"a": []interface{}{math.NaN(), 0, 1}})
  // How to convert b to json?
  </code></pre>
  
  <p>The below fails.</p>
  
  <pre class="lang-golang prettyprint-override"><code>// decode
  var decodedBson bson.M
  bson.Unmarshal(b, &amp;decodedBson)
  _, err := json.Marshal(decodedBson)
  if err != nil {
      panic(err) // it will be invoked
      // panic: json: unsupported value: NaN
  }
  </code></pre>