diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
index b8119f5..1770afc 100644
a
|
b
|
class Serializer(PythonSerializer):
|
18 | 18 | internal_use_only = False |
19 | 19 | |
20 | 20 | def end_serialization(self): |
| 21 | if self.options.get('indent'): |
| 22 | # The default is (', ', ': '). To eliminate useless whitespaces |
| 23 | # after the comma at the end of each line, the representation is |
| 24 | # changed to (',', ': ') only if indent is used. |
| 25 | self.options['separators'] = (',', ': ') |
21 | 26 | simplejson.dump(self.objects, self.stream, cls=DjangoJSONEncoder, **self.options) |
22 | 27 | |
23 | 28 | def getvalue(self): |
diff --git a/tests/modeltests/serializers/tests.py b/tests/modeltests/serializers/tests.py
index 013438e..d03b08b 100644
a
|
b
|
class JsonSerializerTestCase(SerializersTestBase, TestCase):
|
360 | 360 | ret_list.append(obj_dict["fields"][field_name]) |
361 | 361 | return ret_list |
362 | 362 | |
| 363 | def test_indentation_whitespace(self): |
| 364 | """ Ensure that there are no extraneous spaces after the comma at the |
| 365 | end of each line. |
| 366 | Refs #13182. |
| 367 | """ |
| 368 | from django.core.serializers.json import Serializer |
| 369 | Score.objects.create(score=5.0) |
| 370 | Score.objects.create(score=6.0) |
| 371 | qset = Score.objects.all() |
| 372 | s = Serializer() |
| 373 | self.assertEqual(s.serialize(qset,indent=2), """[ |
| 374 | { |
| 375 | "pk": 1, |
| 376 | "model": "serializers.score", |
| 377 | "fields": { |
| 378 | "score": 5.0 |
| 379 | } |
| 380 | }, |
| 381 | { |
| 382 | "pk": 2, |
| 383 | "model": "serializers.score", |
| 384 | "fields": { |
| 385 | "score": 6.0 |
| 386 | } |
| 387 | } |
| 388 | ]""") |
| 389 | |
363 | 390 | class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase): |
364 | 391 | serializer_name = "json" |
365 | 392 | fwd_ref_str = """[ |