Anvil Community Forum

[Fixed] HTTP API Json UTF8 issue

It seems that there is HTTP API Json UTF8 issue - python 3 basic is used.

result in Chrome and Firefox
{"string1": "明彦", "string2": "ø"}
def get_user(id, **params):
    import json
    unicodeData= {
    "string1": "明彦",
    "string2": u"\u00f8"
    encodedUnicode = json.dumps(unicodeData, ensure_ascii=False)
    return encodedUnicode

I try the same code with Flask and get the expected result:

{"string1": "明彦", "string2": "ø"}

Any help is greatly appreciated

Moved to bug reports, this should just work and we’ll let you know when the implementation is fixed.

As a current workaround you can do the following at the end of your code snippet:

return BlobMedia('application/json; charset=utf-8', bytes(encodedUnicode, 'utf-8'))

Thanks so much @stucork
I manage to make it work with the following code as well

response = anvil.server.HttpResponse(200, encodedUnicode)
response.headers["content-type"] = "application/json"
return response
1 Like

This should now be fixed.

1 Like

Thanks so much, I really appreciate that.