#!/usr/bin/env python

import json, sys

def main():
    nargs = len(sys.argv)
    if nargs == 1:
        f = sys.stdin
    elif nargs == 2:
        f = open(sys.argv[1], 'r')
    else:
        print('Usage: %s file' % sys.argv[0])
        return
    json.dump(json.load(f), sys.stdout, indent=2)

if __name__ == '__main__':
    main()

Add script to reformat json files for humans
Add script to reformat json files for humans

I'm often working with json data that is omits newlines and indentation
for consumption by a machine, but I often need to make sense of it
myself as well. This script is a small wrapper around the Python parser
to reformat the json data with newlines and indentation.
