Skip to content

Instantly share code, notes, and snippets.

@turicas
Created September 9, 2022 15:09
Show Gist options
  • Save turicas/e01aa6595c66a1e7206ef749f4b50d07 to your computer and use it in GitHub Desktop.
Save turicas/e01aa6595c66a1e7206ef749f4b50d07 to your computer and use it in GitHub Desktop.
import argparse
import json
def prettify(filename, indent=2, output_filename=None):
with open(filename) as fobj:
data = json.load(fobj)
with open(output_filename or filename, mode="w") as fobj:
json.dump(data, fobj, indent=indent)
if __name__ == "__main__":
parser = argparser.ArgumentParser()
parser.add_argument("input_filename")
parser.add_argument("--output-filename")
parser.add_argument("--indent", default=2)
args = parser.parse_args()
prettify(filename, indent=args.indent, output_filename=args.output_filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment