diff -r 2159ff4595b7 Lib/json/encoder.py --- a/Lib/json/encoder.py Fri Oct 26 19:35:00 2012 +0300 +++ b/Lib/json/encoder.py Fri Oct 26 17:14:21 2012 -0400 @@ -274,7 +274,7 @@ if _indent is not None: _current_indent_level += 1 newline_indent = '\n' + _indent * _current_indent_level - separator = _item_separator + newline_indent + separator = _item_separator.rstrip() + newline_indent buf += newline_indent else: newline_indent = None @@ -326,7 +326,7 @@ if _indent is not None: _current_indent_level += 1 newline_indent = '\n' + _indent * _current_indent_level - item_separator = _item_separator + newline_indent + item_separator = _item_separator.rstrip() + newline_indent yield newline_indent else: newline_indent = None diff -r 2159ff4595b7 Lib/test/json_tests/test_indent.py --- a/Lib/test/json_tests/test_indent.py Fri Oct 26 19:35:00 2012 +0300 +++ b/Lib/test/json_tests/test_indent.py Fri Oct 26 17:14:21 2012 -0400 @@ -58,6 +58,28 @@ # indent=None is more compact check(None, '{"3": 1}') + def test_no_trailing_space_after_list_item(self): + # Using default separator + output = self.dumps(['foo', 'bar'], indent=2) + expected = '[\n "foo",\n "bar"\n]' + self.assertEqual(output, expected) + + # Using custom separator + output = self.dumps(['foo', 'bar'], indent=2, separators=(' , ', ': ')) + expected = '[\n "foo" ,\n "bar"\n]' + self.assertEqual(output, expected) + + def test_no_trailing_space_after_dict_item(self): + # Using default separator + output = self.dumps({'foo': 1, 'bar': 2}, indent=2) + expected = '{\n "foo": 1,\n "bar": 2\n}' + self.assertEqual(output, expected) + + # Using custom separator + output = self.dumps({'foo': 1, 'bar': 2}, indent=2, separators=(' , ', ': ')) + expected = '{\n "foo": 1 ,\n "bar": 2\n}' + self.assertEqual(output, expected) + class TestPyIndent(TestIndent, PyTest): pass class TestCIndent(TestIndent, CTest): pass