This commit is contained in:
David Fischer 2017-05-12 15:43:02 +00:00 committed by GitHub
commit cfc012a102
3 changed files with 17 additions and 3 deletions

View File

@ -362,6 +362,16 @@ The default style is to return minified responses, in line with [Heroku's API de
Default: `True`
#### SORTED_JSON
When set to `True`, keys in JSON responses will be sorted. For example:
{"email": "jane@example", "is_admin": false, "username": "jane"}
When set to `False`, the JSON responses are arbitrarily ordered.
Default: `False`
#### COERCE_DECIMAL_TO_STRING
When returning decimal objects in API representations that do not support a native decimal type, it is normally best to return the value as a string. This avoids the loss of precision that occurs with binary floating point implementations.

View File

@ -100,9 +100,12 @@ class JSONRenderer(BaseRenderer):
separators = INDENT_SEPARATORS
ret = json.dumps(
data, cls=self.encoder_class,
indent=indent, ensure_ascii=self.ensure_ascii,
separators=separators
data,
cls=self.encoder_class,
indent=indent,
ensure_ascii=self.ensure_ascii,
separators=separators,
sort_keys=api_settings.SORTED_JSON,
)
# On python 2.x json.dumps() returns bytestrings if ensure_ascii=True,

View File

@ -110,6 +110,7 @@ DEFAULTS = {
# Encoding
'UNICODE_JSON': True,
'COMPACT_JSON': True,
'SORTED_JSON': False,
'COERCE_DECIMAL_TO_STRING': True,
'UPLOADED_FILES_USE_URL': True,