Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
4 changes: 3 additions & 1 deletion flask/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down