2016-07-23 16:46:44 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
ARGS = sys.argv[1:]
|
|
|
|
|
|
|
|
if not os.isatty(0):
|
|
|
|
data = sys.stdin.read()
|
|
|
|
else:
|
2016-11-07 20:57:42 +00:00
|
|
|
with open(ARGS.pop(0)) as f:
|
2016-07-23 16:46:44 +01:00
|
|
|
data = '\n'.join(f.readlines())
|
|
|
|
|
|
|
|
parsed_data = json.dumps(json.loads(data), indent=2, sort_keys=True)
|
|
|
|
|
|
|
|
if ARGS:
|
|
|
|
with open(ARGS[0], 'w') as f:
|
|
|
|
f.write(parsed_data)
|
|
|
|
else:
|
|
|
|
sys.stdout.write(parsed_data)
|