Provide an easy way to have JSON keys sorted.

This commit is contained in:
bmcustodio 2014-10-14 23:36:27 +01:00
parent b3af4d9fe7
commit 6bd2cb69f6

View File

@ -51,6 +51,7 @@ class JSONRenderer(BaseRenderer):
format = 'json'
encoder_class = encoders.JSONEncoder
ensure_ascii = True
sort_keys = False
# We don't set a charset because JSON is a binary encoding,
# that can be encoded as utf-8, utf-16 or utf-32.
@ -84,7 +85,8 @@ class JSONRenderer(BaseRenderer):
ret = json.dumps(
data, cls=self.encoder_class,
indent=indent, ensure_ascii=self.ensure_ascii
indent=indent, ensure_ascii=self.ensure_ascii,
sort_keys=self.sort_keys
)
# On python 2.x json.dumps() returns bytestrings if ensure_ascii=True,