Skip to content

Commit 34b6dce

Browse files
committed
Unify JSONBoundField as_form_field output between py2 and py3
When using json.dumps with indenting, in python2 the default formatting prints whitespace after commas (,) and python3 does not. This can be unified with the separators keyword argument.
1 parent 71a6bdb commit 34b6dce

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rest_framework/utils/serializer_helpers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ def as_form_field(self):
9090
# value will be a JSONString, rather than a JSON primitive.
9191
if not getattr(value, 'is_json_string', False):
9292
try:
93-
value = json.dumps(self.value, sort_keys=True, indent=4)
93+
value = json.dumps(
94+
self.value,
95+
sort_keys=True,
96+
indent=4,
97+
separators=(',', ': '),
98+
)
9499
except (TypeError, ValueError):
95100
pass
96101
return self.__class__(self._field, value, self.errors, self._prefix)

0 commit comments

Comments
 (0)