diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/json/encoder.py | 2 | ||||
-rw-r--r-- | Lib/json/tests/test_indent.py | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py index 1335985..accbde0 100644 --- a/Lib/json/encoder.py +++ b/Lib/json/encoder.py @@ -233,7 +233,7 @@ class JSONEncoder(object): if (_one_shot and c_make_encoder is not None - and not self.indent): + and self.indent is None): _iterencode = c_make_encoder( markers, self.default, _encoder, self.indent, self.key_separator, self.item_separator, self.sort_keys, diff --git a/Lib/json/tests/test_indent.py b/Lib/json/tests/test_indent.py index cd608d9..d45aa85 100644 --- a/Lib/json/tests/test_indent.py +++ b/Lib/json/tests/test_indent.py @@ -2,6 +2,7 @@ from unittest import TestCase import json import textwrap +from io import StringIO class TestIndent(TestCase): def test_indent(self): @@ -39,3 +40,18 @@ class TestIndent(TestCase): self.assertEqual(h1, h) self.assertEqual(h2, h) self.assertEqual(d2, expect) + + def test_indent0(self): + h = {3: 1} + def check(indent, expected): + d1 = json.dumps(h, indent=indent) + self.assertEqual(d1, expected) + + sio = StringIO() + json.dump(h, sio, indent=indent) + self.assertEqual(sio.getvalue(), expected) + + # indent=0 should emit newlines + check(0, '{\n"3": 1\n}') + # indent=None is more compact + check(None, '{"3": 1}') |