Patch by Amaury Forgeot d'Arc, updated by Sando Tosi.
using the JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
If *indent* is a non-negative integer, then JSON array elements and object
- members will be pretty-printed with that indent level. An indent level of 0
- will only insert newlines. ``None`` (the default) selects the most compact
- representation.
+ members will be pretty-printed with that indent level. An indent level of 0,
+ or negative, will only insert newlines. ``None`` (the default) selects the
+ most compact representation.
If *separators* is an ``(item_separator, dict_separator)`` tuple, then it
will be used instead of the default ``(', ', ': ')`` separators. ``(',',
if (_one_shot and c_make_encoder is not None
- and not self.indent and not self.sort_keys):
+ and self.indent is None and not self.sort_keys):
_iterencode = c_make_encoder(
markers, self.default, _encoder, self.indent,
self.key_separator, self.item_separator, self.sort_keys,
import json
import textwrap
+from StringIO import StringIO
class TestIndent(TestCase):
def test_indent(self):
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}')
Library
-------
+- Issue #10019: Fixed regression in json module where an indent of 0 stopped
+ adding newlines and acted instead like 'None'.
+
- Issue #5162: Treat services like frozen executables to allow child spawning
from multiprocessing.forking on Windows.