diff --git a/Doc/library/json.rst b/Doc/library/json.rst --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -141,6 +141,9 @@ Basic Usage indents that many spaces per level. If *indent* is a string (such at '\t'), that string is used to indent each level. + .. versionchanged:: 3.2 + Allow strings for *indent* in addition to integers. + If *separators* is an ``(item_separator, dict_separator)`` tuple, then it will be used instead of the default ``(', ', ': ')`` separators. ``(',', ':')`` is the most compact JSON representation. diff --git a/Lib/test/json_tests/test_indent.py b/Lib/test/json_tests/test_indent.py --- a/Lib/test/json_tests/test_indent.py +++ b/Lib/test/json_tests/test_indent.py @@ -32,16 +32,22 @@ class TestIndent: d1 = self.dumps(h) d2 = self.dumps(h, indent=2, sort_keys=True, separators=(',', ': ')) d3 = self.dumps(h, indent='\t', sort_keys=True, separators=(',', ': ')) + out = StringIO() + self.json.dump(h, fp=out, indent='\t', sort_keys=True, separators=(',', ': ')) + d4 = out.getvalue() h1 = self.loads(d1) h2 = self.loads(d2) h3 = self.loads(d3) + h4 = self.loads(d4) self.assertEqual(h1, h) self.assertEqual(h2, h) self.assertEqual(h3, h) + self.assertEqual(h4, h) self.assertEqual(d2, expect.expandtabs(2)) self.assertEqual(d3, expect) + self.assertEqual(d4, expect) def test_indent0(self): h = {3: 1}