From 9bd4e6d0d7354e7533db6d1dd557af07735fe23c Mon Sep 17 00:00:00 2001 From: Luke Swart Date: Mon, 12 Jun 2017 00:59:42 -0700 Subject: [PATCH 1/2] feat(json.tool) add --indent flag --- Lib/json/tool.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/json/tool.py b/Lib/json/tool.py index 4f3182c0c1e7f1..305b275893e1c3 100644 --- a/Lib/json/tool.py +++ b/Lib/json/tool.py @@ -27,11 +27,14 @@ def main(): help='write the output of infile to outfile') parser.add_argument('--sort-keys', action='store_true', default=False, help='sort the output of dictionaries alphabetically by key') + parser.add_argument('--indent', action='indent', default=4, + help='level of indentation used for pretty printing') options = parser.parse_args() infile = options.infile or sys.stdin outfile = options.outfile or sys.stdout sort_keys = options.sort_keys + indent = options.indent or 4 with infile: try: if sort_keys: @@ -42,7 +45,7 @@ def main(): except ValueError as e: raise SystemExit(e) with outfile: - json.dump(obj, outfile, sort_keys=sort_keys, indent=4) + json.dump(obj, outfile, sort_keys=sort_keys, indent=indent) outfile.write('\n') From c94b5c413a2876a2a56f2d32e7c5e1abf6739481 Mon Sep 17 00:00:00 2001 From: Luke Swart Date: Wed, 14 Jun 2017 17:40:58 -0700 Subject: [PATCH 2/2] feat(json.tool) add type=int to --indent --- Lib/json/tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/json/tool.py b/Lib/json/tool.py index 305b275893e1c3..cc4540fc6a3154 100644 --- a/Lib/json/tool.py +++ b/Lib/json/tool.py @@ -27,7 +27,7 @@ def main(): help='write the output of infile to outfile') parser.add_argument('--sort-keys', action='store_true', default=False, help='sort the output of dictionaries alphabetically by key') - parser.add_argument('--indent', action='indent', default=4, + parser.add_argument('--indent', action='store', default=4, type=int, help='level of indentation used for pretty printing') options = parser.parse_args()