JSON Response Filtering Fails with Non-ASCII Characters

from flask import Flask, jsonify
app = Flask(__name__)

DATA = {"message": {"en-us": "Hello World!", "zh-cn": "你好,世界!"}}

@app.route('/hello_ascii')
def hello_ascii():
    app.json.ensure_ascii = True
    return jsonify(DATA)

@app.route('/hello_no_ascii')
def hello_no_ascii():
    app.json.ensure_ascii = False
    return jsonify(DATA)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)


JSONPath filter: $.message.zh-cn

hello_ascii

before:

{ "message": { "en-us": "Hello World!", "zh-cn": "你好,世界!" } }

after:

[ "你好,世界!" ]

hello_no_ascii

before:

{ "message": { "en-us": "Hello World!", "zh-cn": "你好,世界!" } }

after:

[ "菴�螂ス�御ク也阜��" ]

Please authenticate to join the conversation.

Upvoters
Status

Released

Board

Feedback

Tags

Bug

Date

2 months ago

Author

WantChane

Subscribe to post

Get notified by email when there are changes.