diff Lib/json/encoder.py @ 80631:e63ac05ccfa8

#16333: use (",", ": ") as default separator when indent is specified to avoid trailing whitespace. Patch by Serhiy Storchaka.
author Ezio Melotti <ezio.melotti@gmail.com>
date Thu, 29 Nov 2012 00:42:56 +0200
parents 8b30a764b58d
children 406c6fd7e753
line wrap: on
line diff
--- a/Lib/json/encoder.py	Thu Nov 29 00:37:52 2012 +0200
+++ b/Lib/json/encoder.py	Thu Nov 29 00:42:56 2012 +0200
@@ -127,9 +127,10 @@
         indent level.  An indent level of 0 will only insert newlines.
         None is the most compact representation.
 
-        If specified, separators should be a (item_separator, key_separator)
-        tuple.  The default is (', ', ': ').  To get the most compact JSON
-        representation you should specify (',', ':') to eliminate whitespace.
+        If specified, separators should be an (item_separator, key_separator)
+        tuple.  The default is (', ', ': ') if *indent* is ``None`` and
+        (',', ': ') otherwise.  To get the most compact JSON representation,
+        you should specify (',', ':') to eliminate whitespace.
 
         If specified, default is a function that gets called for objects
         that can't otherwise be serialized.  It should return a JSON encodable
@@ -145,6 +146,8 @@
         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