Why does json.Encoder add an extra line?
<p><a href="https://golang.org/pkg/encoding/json/#NewEncoder" rel="noreferrer"><code>json.Encoder</code></a> seems to behave slightly different than <code>json.Marshal</code>. Specifically it adds a new line at the end of the encoded value. Any idea why is that? It looks like a bug to me.</p>

<pre><code>package main

import "fmt"
import "encoding/json"
import "bytes"

func main() {
    var v string
    v = "hello"
    buf := bytes.NewBuffer(nil)
    json.NewEncoder(buf).Encode(v)
    b, _ := json.Marshal(&amp;v)

    fmt.Printf("%q, %q", buf.Bytes(), b)
}
</code></pre>

<p>This outputs</p>

<pre><code>"\"hello\"\n", "\"hello\""
</code></pre>

<p><a href="http://play.golang.org/p/r0Hwtnd03j" rel="noreferrer"><kbd>Try it in the Playground</kbd></a></p>