diff options
author | Bob Ippolito <bob@redivi.com> | 2011-04-12 11:29:46 -0700 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2011-04-12 11:29:46 -0700 |
commit | 5cad556f7d60a84eda51adca054c51a192c98c09 (patch) | |
tree | 83bba7e62a21a7c54dcaf84eddd08c616c131ebf /simplejson | |
parent | 1a371353a0fdf324f4b98c9f3e13439724066655 (diff) | |
download | simplejson-5cad556f7d60a84eda51adca054c51a192c98c09.tar.gz |
Trailing whitespace after commas no longer emitted when indent is used
Diffstat (limited to 'simplejson')
-rw-r--r-- | simplejson/encoder.py | 2 | ||||
-rw-r--r-- | simplejson/tests/test_indent.py | 17 |
2 files changed, 19 insertions, 0 deletions
diff --git a/simplejson/encoder.py b/simplejson/encoder.py index 468d1bd..f43f6f4 100644 --- a/simplejson/encoder.py +++ b/simplejson/encoder.py @@ -165,6 +165,8 @@ class JSONEncoder(object): self.indent = indent if separators is not None: self.item_separator, self.key_separator = separators + elif indent is not None: + self.item_separator = ',' if default is not None: self.default = default self.encoding = encoding diff --git a/simplejson/tests/test_indent.py b/simplejson/tests/test_indent.py index 75a2f6e..1e6bdb1 100644 --- a/simplejson/tests/test_indent.py +++ b/simplejson/tests/test_indent.py @@ -67,3 +67,20 @@ class TestIndent(TestCase): check(0, '{\n"3": 1\n}') # indent=None is more compact check(None, '{"3": 1}') + + def test_separators(self): + lst = [1,2,3,4] + expect = '[\n1,\n2,\n3,\n4\n]' + expect_spaces = '[\n1, \n2, \n3, \n4\n]' + # Ensure that separators still works + self.assertEquals( + expect_spaces, + json.dumps(lst, indent=0, separators=(', ', ': '))) + # Force the new defaults + self.assertEquals( + expect, + json.dumps(lst, indent=0, separators=(',', ': '))) + # Added in 2.1.4 + self.assertEquals( + expect, + json.dumps(lst, indent=0))
\ No newline at end of file |