diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2012-11-28 22:36:42 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2012-11-28 22:36:42 (GMT) |
commit | 57af3bf1586718b650333a6230e34c279d826f92 (patch) | |
tree | b8de4c41abc22106a184ea1e9ae1a45ea0dcd439 /Doc | |
parent | eff1738e011ad7eb4479485557095c4a197d48ff (diff) | |
parent | d654dedbbb1116bfed989aafd2ee7a004828546b (diff) | |
download | cpython-57af3bf1586718b650333a6230e34c279d826f92.zip cpython-57af3bf1586718b650333a6230e34c279d826f92.tar.gz cpython-57af3bf1586718b650333a6230e34c279d826f92.tar.bz2 |
#16333: merge with 3.2.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/json.rst | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Doc/library/json.rst b/Doc/library/json.rst index f9547cb..bdb6436 100644 --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -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. |