[issue28984] json.dump + indent creates trailing extra spaces

Josh Rosenberg report at bugs.python.org
Thu Dec 15 19:43:13 EST 2016


Josh Rosenberg added the comment:

This is documented behavior for Python 2 ( https://docs.python.org/2/library/json.html#basic-usage ):

>Note: Since the default item separator is ', ', the output might include trailing whitespace when indent is specified. You can use separators=(',', ': ') to avoid this.

and also:

If specified, separators should be an (item_separator, key_separator) tuple. By default, (', ', ': ') are used. To get the most compact JSON representation, you should specify (',', ':') to eliminate whitespace.

Python 3 gives a different guarantee (dynamically chosen default separators based on the value of indent), and it follows that contract.

Given it's clearly documented, easily worked around, and largely harmless, I see no strong argument for backporting the Python 3 behavior to the legacy codebase.

----------
nosy: +josh.r

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28984>
_______________________________________


More information about the Python-bugs-list mailing list