|
39 | 39 | Pretty printing:: |
40 | 40 |
|
41 | 41 | >>> import json |
42 | | - >>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4) |
43 | | - >>> print('\n'.join([l.rstrip() for l in s.splitlines()])) |
| 42 | + >>> print(json.dumps({'4': 5, '6': 7}, sort_keys=True, |
| 43 | + ... indent=4, separators=(',', ': '))) |
44 | 44 | { |
45 | 45 | "4": 5, |
46 | 46 | "6": 7 |
@@ -146,7 +146,9 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, |
146 | 146 | If ``indent`` is a non-negative integer, then JSON array elements and |
147 | 147 | object members will be pretty-printed with that indent level. An indent |
148 | 148 | level of 0 will only insert newlines. ``None`` is the most compact |
149 | | - representation. |
| 149 | + representation. Since the default item separator is ``', '``, the |
| 150 | + output might include trailing whitespace when ``indent`` is specified. |
| 151 | + You can use ``separators=(',', ': ')`` to avoid this. |
150 | 152 |
|
151 | 153 | If ``separators`` is an ``(item_separator, dict_separator)`` tuple |
152 | 154 | then it will be used instead of the default ``(', ', ': ')`` separators. |
@@ -207,7 +209,9 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, |
207 | 209 | If ``indent`` is a non-negative integer, then JSON array elements and |
208 | 210 | object members will be pretty-printed with that indent level. An indent |
209 | 211 | level of 0 will only insert newlines. ``None`` is the most compact |
210 | | - representation. |
| 212 | + representation. Since the default item separator is ``', '``, the |
| 213 | + output might include trailing whitespace when ``indent`` is specified. |
| 214 | + You can use ``separators=(',', ': ')`` to avoid this. |
211 | 215 |
|
212 | 216 | If ``separators`` is an ``(item_separator, dict_separator)`` tuple |
213 | 217 | then it will be used instead of the default ``(', ', ': ')`` separators. |
|
0 commit comments