From 4cdc4be2e6d13e86799291b64ed5462b8bb8ce07 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Wed, 9 Mar 2016 15:43:52 -0500 Subject: [PATCH] Pretty print json output when writing to a file It's the opposite of fun to read a single line of json output when generating the graph results, so if using the -o option to write to a file, indent the output for readability. Change-Id: I091ee2ade51def2d59cdeadb792e56746f8882a2 --- elastic_recheck/cmd/graph.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/elastic_recheck/cmd/graph.py b/elastic_recheck/cmd/graph.py index 9aee62f1..0496cae3 100755 --- a/elastic_recheck/cmd/graph.py +++ b/elastic_recheck/cmd/graph.py @@ -231,7 +231,9 @@ def main(): out = sys.stdout try: - out.write(json.dumps(jsondata)) + # indent the json output if we're writing to a file + indent = 4 if args.output else None + out.write(json.dumps(jsondata, indent=indent)) finally: out.close()