mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
#16333: document a way to get rid of trailing whitespace when indent is used.
This commit is contained in:
parent
74120996f5
commit
d654dedbbb
3 changed files with 26 additions and 6 deletions
|
@ -42,7 +42,8 @@ Compact encoding::
|
|||
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,12 @@ Basic Usage
|
|||
.. versionchanged:: 3.2
|
||||
Allow strings for *indent* in addition to integers.
|
||||
|
||||
.. note::
|
||||
|
||||
Since the default item separator is ``', '``, the output might include
|
||||
trailing whitespace when *indent* is specified. You can use
|
||||
``separators=(',', ': ')`` to avoid this.
|
||||
|
||||
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 +400,12 @@ Encoders and Decoders
|
|||
.. versionchanged:: 3.2
|
||||
Allow strings for *indent* in addition to integers.
|
||||
|
||||
.. note::
|
||||
|
||||
Since the default item separator is ``', '``, the output might include
|
||||
trailing whitespace when *indent* is specified. You can use
|
||||
``separators=(',', ': ')`` to avoid this.
|
||||
|
||||
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue