Werkzeug: About JSON encoding in werkzeug.utils.py

Created on 12 Jan 2016  ·  3Comments  ·  Source: pallets/werkzeug

def get_content_type(mimetype, charset):
"""Returns the full content type string with charset for a mimetype.
If the mimetype represents text the charset will be appended as charset
parameter, otherwise the mimetype is returned unchanged.
:param mimetype: the mimetype to be used as content type.
:param charset: the charset to be appended in case it was a text mimetype.
:return: the content type.
"""
if mimetype.startswith('text/') or \
mimetype == 'application/xml' or \
(mimetype.startswith('application/') and
mimetype.endswith('+xml')):
mimetype += '; charset=' + charset
return mimetype

I was just beginning to touch this, have a encoding problems.
Why not judge “mimetype == 'application/json' ”?

Most helpful comment

JSON is always UTF-8.

All 3 comments

JSON is always UTF-8.

@caiz there is another discussion: https://github.com/request/request/issues/383, and more details about JSON charset: http://tools.ietf.org/html/rfc4627#section-3

thank you for your help.

Was this page helpful?
0 / 5 - 0 ratings