Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add `JSON_ASCII` option to remove unneeded decoding on client side #535

Closed
wants to merge 1 commit into from

3 participants

@bobuk

This patch will remove weird behaviour and add JSON_ASCII configuration options.
I also had an audacity to correct mimetype encoding for JSON to 'utf-8' by default.

I don't sure what that patch must be applied in master but I just want to place it here for other guys :)

@bobuk bobuk Currently Flask use default ``ensure_ascii=True`` for jsonify.
This patch will remove weird behaviour and add `JSON_ASCII` configuration options.
I also had an audacity to correct mimetype encoding for JSON to 'utf-8' by default.
c2feddf
@travisbot

This pull request passes (merged c2feddf into ee3e251).

@mitsuhiko mitsuhiko closed this in 8339cb3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 1, 2012
  1. @bobuk

    Currently Flask use default ``ensure_ascii=True`` for jsonify.

    bobuk authored
    This patch will remove weird behaviour and add `JSON_ASCII` configuration options.
    I also had an audacity to correct mimetype encoding for JSON to 'utf-8' by default.
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 1 deletion.
  1. +5 −0 docs/config.rst
  2. +3 −1 flask/helpers.py
View
5 docs/config.rst
@@ -142,6 +142,11 @@ The following configuration values are used internally by Flask:
``PREFERRED_URL_SCHEME`` The URL scheme that should be used for
URL generation if no URL scheme is
available. This defaults to ``http``.
+``JSON_ASCII`` By default Flask serialize object to
+ ascii-encoded JSON. If this is set to
+ ``False`` Flask will not encode to ascii
+ and output strings as-is, in system
+ encoding (i.e. in UTF-8).
================================= =========================================
.. admonition:: More on ``SERVER_NAME``
View
4 flask/helpers.py
@@ -195,7 +195,9 @@ def get_current_user():
if __debug__:
_assert_have_json()
return current_app.response_class(json.dumps(dict(*args, **kwargs),
- indent=None if request.is_xhr else 2), mimetype='application/json')
+ indent=None if request.is_xhr else 2,
+ ensure_ascii=current_app.config.get('JSON_ASCII', True)),
+ mimetype='application/json; charset=utf-8')
def make_response(*args):
Something went wrong with that request. Please try again.