Escape unicode characters in Go JSON so the output matches Python
<p>In Python 2.7, if I encode JSON I get unicode-escaped strings:</p>

<pre><code>&gt;&gt;&gt; import json
&gt;&gt;&gt; s = {"text": "三杯雞"}
&gt;&gt;&gt; print(json.dumps(s))
</code></pre>

<p>it gives this output:</p>

<pre><code>{"text": "\u4e09\u676f\u96de"}
</code></pre>

<p>But in Go, similar code:</p>

<pre><code>package main

import (
    "encoding/json"
    "fmt"
)

type Food struct {
    Name string `json:"name"`
}

func main() {
    food := Food{Name: "三杯雞"}
    v, _ := json.Marshal(food)
    fmt.Println(string(v))
}
</code></pre>

<p>Gives this:</p>

<pre><code>{"name":"三杯雞"}
</code></pre>

<p>The Chinese characters are not escaped. I am porting API endpoints from Python to Go - how can I get it to have the same escaped output as Python?</p>

<p>I tried variations using <code>strconv.QuoteToASCII</code>, but they result in the unicode being double-escaped:</p>

<pre><code>func main() {
    s := strconv.QuoteToASCII("三杯雞")
    s = strings.Trim(s, "\"")
    food := Food{Name: s}
    v, _ := json.Marshal(food)
    fmt.Println(string(v))
}
</code></pre>

<p>Outputs:</p>

<pre><code>{"name":"\\u4e09\\u676f\\u96de"}
</code></pre>