This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dhimmel
Recipients dhimmel, methane
Date 2017-02-23.20:05:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The utility of `python -m json.tool` would increase if users could specify the indent level.

Example use case: newlines in a JSON document are important for readability and the ability to open in a text editor. However, if the file is large, you can save space by decreasing the indent level.

I added an --indent argument to json.tool in However, design discussion is required since indent can take an int, string, or None. In addition, a indent string is a tab, which is difficult to pass via a command line argument.

Currently, I added the following function to convert the indent option to the indent parameter of json.dump:

def parse_indent(indent):
    """Parse the argparse indent argument."""
    if indent == 'None':
        return None
    if indent == r'\t':
        return '\t'
        return int(indent)
    except ValueError:
        return indent

@inada.naoki mentioned the special casing is undesirable. I agree, but can't think of an alternative. Advice appreciated.
Date User Action Args
2017-02-23 20:05:57dhimmelsetrecipients: + dhimmel, methane
2017-02-23 20:05:56dhimmelsetmessageid: <>
2017-02-23 20:05:56dhimmellinkissue29636 messages
2017-02-23 20:05:56dhimmelcreate