Author dhimmel
Recipients dhimmel, inada.naoki
Date 2017-02-23.20:05:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1487880356.98.0.87296874253.issue29636@psf.upfronthosting.co.za>
In-reply-to
Content
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 https://github.com/python/cpython/pull/201. 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'
    try:
        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.
History
Date User Action Args
2017-02-23 20:05:57dhimmelsetrecipients: + dhimmel, inada.naoki
2017-02-23 20:05:56dhimmelsetmessageid: <1487880356.98.0.87296874253.issue29636@psf.upfronthosting.co.za>
2017-02-23 20:05:56dhimmellinkissue29636 messages
2017-02-23 20:05:56dhimmelcreate