mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Fix key ordering in json. (sort if it's a sorted dictc representation, or not otherwise)
This commit is contained in:
parent
648d2be29b
commit
db6b5a990b
|
@ -54,7 +54,6 @@ class JSONRenderer(BaseRenderer):
|
||||||
# E.g. If we're being called by the BrowseableAPIRenderer.
|
# E.g. If we're being called by the BrowseableAPIRenderer.
|
||||||
renderer_context = renderer_context or {}
|
renderer_context = renderer_context or {}
|
||||||
indent = renderer_context.get('indent', None)
|
indent = renderer_context.get('indent', None)
|
||||||
sort_keys = indent and True or False
|
|
||||||
|
|
||||||
if accepted_media_type:
|
if accepted_media_type:
|
||||||
# If the media type looks like 'application/json; indent=4',
|
# If the media type looks like 'application/json; indent=4',
|
||||||
|
@ -63,12 +62,10 @@ class JSONRenderer(BaseRenderer):
|
||||||
indent = params.get('indent', indent)
|
indent = params.get('indent', indent)
|
||||||
try:
|
try:
|
||||||
indent = max(min(int(indent), 8), 0)
|
indent = max(min(int(indent), 8), 0)
|
||||||
sort_keys = True
|
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
indent = None
|
indent = None
|
||||||
|
|
||||||
return json.dumps(data, cls=self.encoder_class,
|
return json.dumps(data, cls=self.encoder_class, indent=indent)
|
||||||
indent=indent, sort_keys=sort_keys)
|
|
||||||
|
|
||||||
|
|
||||||
class JSONPRenderer(JSONRenderer):
|
class JSONPRenderer(JSONRenderer):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user