◐ Shell
clean mode source ↗

Allow setting indent width or character in json.tool by int-ua · Pull Request #426 · python/cpython

@int-ua

Allows having shorter or wider indentation or using tabs for it, like this:

$ python3 -m json.tool input.json --indent=$'\t'

@the-knights-who-say-ni

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow these steps to help rectify the issue:

  1. If you don't have an account on b.p.o, please create one
  2. Make sure your GitHub username is listed in "Your Details" at b.p.o
  3. If you have not already done so, please sign the PSF contributor agreement. The "bugs.python.org username " requested by the form is the "Login name" field under "Your Details".
  4. If you just signed the CLA, please wait at least one US business day and then check "Your Details" on bugs.python.org to see if your account has been marked as having signed the CLA (the delay is due to a person having to manually check your signed CLA)
  5. Reply here saying you have completed the above steps

Thanks again to your contribution and we look forward to looking at it!

@mention-bot

@serhiy-storchaka

@int-ua

Sorry, looks like I've made a typo when searching before posting.

@int-ua

Wait, #345 doesn't allow tabs.

@dhimmel

@int-ua see conversation here. Initially, I had implemented a solution that supported indent='\t', indent=None, and indent corresponding to any int or string. However, the reviewers didn't like the special casing, which I agree is undesirable.

@serhiy-storchaka mentioned:

You can use external commands like unexpand for converting spaces to tabs.

It doesn't look like your PR currently supports setting an int indent. I guess you could always pass --indent=" " for two spaces. Let's direct further design discussion to bpo-29636.

@int-ua

It did allow integers, see line 38. Also, to prevent misunderstanding: I don't care at all whose commit is going to be merged, I really appreciate all Python authors' work and I just want tabs, a character created specifically to set indent level. Now, that's all, moving to BPO.

dhimmel

outfile = options.outfile or sys.stdout
sort_keys = options.sort_keys
try:
indent = int(options.indent)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad... clearly supports int!

jaraco pushed a commit that referenced this pull request

Dec 2, 2022