title: Flask JSONEncoder set ensure_ascii to False
body: <p>I'm working on a small flask app in which I want to return strings containing umlauts (in general German special characters, e.g 'ß'). As the default <code>JSONEncoder</code> in flask has <code>ensure_ascii=True</code>, this will always convert my string </p>
  
  <pre><code>Hauptstraße 213
  </code></pre>
  
  <p>to this:</p>
  
  <pre><code>Hauptstra\u00dfe 213
  </code></pre>
  
  <p>My first approach was to just create a very basic custom <code>JSONEncoder</code></p>
  
  <pre><code>class NonAsciiJSONEncoder(json.JSONEncoder):
      def __init__(self, **kwargs):
          super(NonAsciiJSONEncoder, self).__init__(kwargs)
          self.ensure_ascii = False 
  </code></pre>
  
  <p>If I use this, by setting</p>
  
  <pre><code>app.json_encoder = NonAsciiJSONEncoder
  </code></pre>
  
  <p>my <code>return jsonify(...)</code> will actually return the string containing 'ß'. </p>
  
  <p>However, as <code>ensure_ascii</code> is an attribute of the default Encoder, I thought it might be better to just change it by setting it to <code>False</code></p>
  
  <pre><code>app.json_encoder.ensure_ascii = False
  </code></pre>
  
  <p>This will actually set the property to False which I checked before returning. But somehow, the string is still returned without 'ß' but with <code>\u00df</code>. </p>
  
  <p>How can this be, as all I'm doing in my custom Encoder, is setting this attribute to <code>False</code>? </p>