New submission from Daniel Himmelstein: 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. ---------- components: IO messages: 288479 nosy: dhimmel, inada.naoki priority: normal pull_requests: 230 severity: normal status: open title: Specifying indent in the json.tool command type: enhancement versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29636> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com