diff -r 1d515909e624 Doc/library/json.rst --- a/Doc/library/json.rst Wed Nov 28 02:47:45 2012 -0800 +++ b/Doc/library/json.rst Wed Nov 28 17:59:08 2012 +0200 @@ -42,7 +42,8 @@ Pretty printing:: >>> import json - >>> print(json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)) + >>> print(json.dumps({'4': 5, '6': 7}, sort_keys=True, + ... indent=4, separators=(',', ': '))) { "4": 5, "6": 7 @@ -155,6 +156,11 @@ .. versionchanged:: 3.2 Allow strings for *indent* in addition to integers. + .. note:: + + Use ``separators=(',', ': ')`` instead the default *separators* to supress + an extra space preciding the newline. + 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. @@ -393,6 +399,11 @@ .. versionchanged:: 3.2 Allow strings for *indent* in addition to integers. + .. note:: + + Use ``separators=(',', ': ')`` instead the default *separators* to supress + an extra space preciding the newline. + If specified, *separators* should be an ``(item_separator, key_separator)`` tuple. The default is ``(', ', ': ')``. To get the most compact JSON representation, you should specify ``(',', ':')`` to eliminate whitespace. diff -r 1d515909e624 Lib/json/tool.py --- a/Lib/json/tool.py Wed Nov 28 02:47:45 2012 -0800 +++ b/Lib/json/tool.py Wed Nov 28 17:59:08 2012 +0200 @@ -29,7 +29,7 @@ obj = json.load(infile) except ValueError as e: raise SystemExit(e) - json.dump(obj, outfile, sort_keys=True, indent=4) + json.dump(obj, outfile, sort_keys=True, indent=4, separators=(',', ': ')) outfile.write('\n')