gh-146061: Fix contradicting sentences in json docs#146095
gh-146061: Fix contradicting sentences in json docs#146095jonathandung wants to merge 16 commits intopython:mainfrom
Conversation
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
|
PR edited. See @serhiy-storchaka's comment. |
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
| object members will be pretty-printed with that indent level. An indent | ||
| level of 0 will only insert newlines. ``None`` is the most compact | ||
| representation. | ||
| level of 0 will only insert newlines. ``None`` gives a compact |
There was a problem hiding this comment.
If ``indent`` is ``None`` (the default), no newlines are inserted.
There was a problem hiding this comment.
This is not true. indent=None does not give a compact representation. indent=None gives the result of the same size as indent=0. I would not mention compactness here, it is misleading.
There was a problem hiding this comment.
It does give a compact representation.
> python -c "print(__import__('json').dumps([{'a': 1, 'b': [2, 3], 'c': {'d': 4, 'e': [5, 6]}}, 7]))"
[{"a": 1, "b": [2, 3], "c": {"d": 4, "e": [5, 6]}}, 7]
> python -c "print(__import__('json').dumps([{'a': 1, 'b': [2, 3], 'c': {'d': 4, 'e': [5, 6]}}, 7], indent=None))"
[{"a": 1, "b": [2, 3], "c": {"d": 4, "e": [5, 6]}}, 7]
> python -c "print(__import__('json').dumps([{'a': 1, 'b': [2, 3], 'c': {'d': 4, 'e': [5, 6]}}, 7], indent=0))"
[
{
"a": 1,
"b": [
2,
3
],
"c": {
"d": 4,
"e": [
5,
6
]
}
},
7
]There was a problem hiding this comment.
The term "compact" is ambiguous and misleading. It is not explicitly defined, and the only example for compact encoding uses separators=(',', ':'). It can be understood as a synonym of "the most compact".
What index=None does is making the output single-line, or not inserting newlines.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Also update the docstring for dumps().
Done |
|
Please review |
|
@jonathandung Most python developers are volunteers, so it can take a bit of time before your PR gets (another) review. Also see the dev guide https://devguide.python.org/getting-started/pull-request-lifecycle/#reviewing |
|
Understood, thanks |
Closes #146061.
Changed the description under the
indentparameter tojson.dump, such that it no longer opposes that underseparators.📚 Documentation preview 📚: https://cpython-previews--146095.org.readthedocs.build/