title: Why does json.dumps escape non-ascii characters with "\uxxxx"
body: <p>In Python 2, the function <code>json.dumps()</code> will ensure that all non-ascii characters are escaped as <code>\uxxxx</code>. </p>
  
  <p><a href="https://docs.python.org/2/library/json.html#basic-usage" rel="nofollow">Python 2 Json</a></p>
  
  <p>But isn't this quite confusing because <code>\uxxxx</code> is a unicode character and should be used inside a unicode string. </p>
  
  <p>The output of <code>json.dumps()</code> is a <code>str</code>, which is a byte string in Python 2. And thus shouldn't it escape characters as <code>\xhh</code> ?</p>
  
  <pre><code>&gt;&gt;&gt; unicode_string = u"\u00f8"
  &gt;&gt;&gt; print unicode_string
  ø
  &gt;&gt;&gt; print json.dumps(unicode_string)
  "\u00f8"
  &gt;&gt;&gt; unicode_string.encode("utf8")
  '\xc3\xb8'
  </code></pre>