Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JSONRenderer that doesn't force ascii
class UnicodeJSONRenderer(BaseRenderer):
Renderer which serializes to JSON
media_type = 'application/json'
format = 'json'
def render(self, obj=None, media_type=None):
Renders *obj* into serialized JSON.
if obj is None:
return ''
# If the media type looks like 'application/json; indent=4', then
# pretty print the result.
indent = get_media_type_params(media_type).get('indent', None)
sort_keys = False
indent = max(min(int(indent), 8), 0)
sort_keys = True
except (ValueError, TypeError):
indent = None
return json.dumps(obj, cls=DateTimeAwareJSONEncoder, ensure_ascii=False, indent=indent, sort_keys=sort_keys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.