summaryrefslogtreecommitdiff
path: root/Doc/library/json.rst
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2012-11-29 00:22:30 +0200
committerEzio Melotti <ezio.melotti@gmail.com>2012-11-29 00:22:30 +0200
commit3a237ebcaaf80ac293d4ef3e9b430b81fd7c236b (patch)
tree19b89d60f8615bcc9be9e93e1e0c4fc40cce3b82 /Doc/library/json.rst
parent0d68ab3f481ab6c8ecb0d83762b4cd9fb9208356 (diff)
downloadcpython-git-3a237ebcaaf80ac293d4ef3e9b430b81fd7c236b.tar.gz
#16333: document a way to get rid of trailing whitespace when indent is used.
Diffstat (limited to 'Doc/library/json.rst')
-rw-r--r--Doc/library/json.rst15
1 files changed, 14 insertions, 1 deletions
diff --git a/Doc/library/json.rst b/Doc/library/json.rst
index e5ef1e7d74..71020fd3cb 100644
--- a/Doc/library/json.rst
+++ b/Doc/library/json.rst
@@ -43,7 +43,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
@@ -153,6 +154,12 @@ Basic Usage
or negative, will only insert newlines. ``None`` (the default) selects the
most compact representation.
+ .. 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.
@@ -410,6 +417,12 @@ Encoders and Decoders
level. An indent level of 0 will only insert newlines. ``None`` is the most
compact representation.
+ .. 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.