◐ Shell
reader mode source ↗
Skip to content

bpo-29636: Add --indent / --no-indent arguments to json.tool#345

Merged
methane merged 8 commits into
python:masterfrom
dhimmel:indent
Dec 4, 2019
Merged

bpo-29636: Add --indent / --no-indent arguments to json.tool#345
methane merged 8 commits into
python:masterfrom
dhimmel:indent

Conversation

@dhimmel

@dhimmel dhimmel commented Feb 27, 2017

Copy link
Copy Markdown
Contributor

From #201 which is being split into two pull requests.

Tagging @serhiy-storchaka, @berkerpeksag, @methane who helped review #201.

Closes http://bugs.python.org/issue29636.

https://bugs.python.org/issue29636

@dhimmel

dhimmel commented Feb 27, 2017

Copy link
Copy Markdown
Contributor Author

Note to rebase on #346 which should be merged first.

@vstinner vstinner added the type-feature A feature request or enhancement label Mar 2, 2017
@serhiy-storchaka

Copy link
Copy Markdown
Member

Spaces after comma and semicolon are not just for readability. They make JSON compatible with YAML 1.0.

@vstinner

vstinner commented Mar 3, 2017 via email

Copy link
Copy Markdown
Member

@serhiy-storchaka

Copy link
Copy Markdown
Member

This is not the right place for the design discussion. Lets continue it on the bug tracker.

@dhimmel

dhimmel commented Mar 3, 2017

Copy link
Copy Markdown
Contributor Author

This is not the right place for the design discussion. Lets continue it on the bug tracker.

@serhiy-storchaka and @Haypo I updated bpo-29636 with a summary of the design discussion thus far.

I propose continuing this pull request with only --indent and --no-indent. If we end up reaching consensus to add --compact, that can be added in the future. I think it would fit in nicely alongside --indent and --no-indent. In other words, it's not pressing to decide on --compact right now.

@dhimmel

dhimmel commented Mar 16, 2017

Copy link
Copy Markdown
Contributor Author

#346 has been merged and this PR rebased.

@serhiy-storchaka, @berkerpeksag, @methane and @Haypo: open for review. No more outstanding changes on my end.

Originall from python#2720

Set default option for infile and outfile as per
python#2720 (review)

Use --sort-keys help message based on the json.tool docs at
https://docs.python.org/3.6/library/json.html#basic-usage:

Remove commens as per https://bugs.python.org/msg298692.
Code was descriptive without the comments.
@methane

methane commented Feb 22, 2018

Copy link
Copy Markdown
Member

@dhimmel Please add NEWS entry.

@dhimmel

dhimmel commented Feb 22, 2018

Copy link
Copy Markdown
Contributor Author

Thanks @methane for ba16891 which merges in the changes from #5315 (dict order guaranteed as of Python 3.7).

I'll get working on the NEWS entry.

Use `blurb add` command to assist with adding the NEWS entry.
@dhimmel

dhimmel commented Feb 22, 2018

Copy link
Copy Markdown
Contributor Author

Ready from my end.

As of b8fee34, --help prints the following message:

usage: python -m json.tool [-h] [--sort-keys]
                           [--indent INDENT | --tab | --no-indent | --compact]
                           [infile] [outfile]

A simple command line interface for json module to validate and pretty-print
JSON objects.

positional arguments:
  infile           a JSON file to be validated or pretty-printed
  outfile          write the output of infile to outfile

optional arguments:
  -h, --help       show this help message and exit
  --sort-keys      sort the output of dictionaries by key
  --indent INDENT  separate items with newlines and use this number of spaces
                   for indentation
  --tab            separate items with newlines and use tabs for indentation
  --no-indent      separate items with spaces rather than newlines
  --compact        suppress all whitespace separation (most compact)

21 hidden items Load more…
@serhiy-storchaka

Copy link
Copy Markdown
Member

What if pass conflicting options? --indent=4 and --tab? --indent=4 and --compact?

@dhimmel

dhimmel commented Feb 22, 2018

Copy link
Copy Markdown
Contributor Author

What if pass conflicting options? --indent=4 and --tab? --indent=4 and --compact?

The intention is to disallow users from passing multiple whitespace options with argparse's add_mutually_exclusive_group. The implementation will, in most cases, detect and raise an error if multiple whitespace arguments are provided. However, there is an argparse issue (bpo-18943) where mutual exclusivity is not enforced when --indent=4 is specified (since 4 is default).

For example, --compact --tab or --indent=3 --compact or --indent=4 --compact --tab will all throw errors of the form:

python -m json.tool: error: argument --tab: not allowed with argument --compact

--indent=4 --compact (or --indent=4 --tab) does not throw an error. In the case that --indent=4 is specified with --compact, --tab, or no-indent, the later will take precedent.

@mya12321

mya12321 commented Apr 8, 2018

Copy link
Copy Markdown

I hope this feature can be merged ASAP, it's really helpful as a cross-platform command line utility.

@dhimmel

dhimmel commented Apr 8, 2018

Copy link
Copy Markdown
Contributor Author

I hope this feature can be merged ASAP

@mya12321 the most effective way for you to support this PR would be to chime in on the issue. At present, I think there is some hesitancy to add additional arguments, so if you explain your use case that may be helpful. But as far as I understand, this discussion should go on the bug tracker and not on GitHub.

@methane

methane commented Dec 1, 2019

Copy link
Copy Markdown
Member

Would you resolve the conflict?

@methane methane merged commit 0325794 into python:master Dec 4, 2019
@vstinner

vstinner commented Dec 4, 2019

Copy link
Copy Markdown
Member

Well done @dhimmel and thanks for your tenacity!

jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
jaraco pushed a commit that referenced this pull request Dec 2, 2022
Bumps [gidgethub](https://github.com/brettcannon/gidgethub) from 4.1.0 to 4.1.1.
- [Release notes](https://github.com/brettcannon/gidgethub/releases)
- [Changelog](https://github.com/brettcannon/gidgethub/blob/master/docs/changelog.rst)
- [Commits](gidgethub/gidgethub@v4.1.0...v4.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants