Commit cb1106a3 authored by Mathieu Giraud's avatar Mathieu Giraud
Browse files

tools/ argparse, more flexible output (-1, -u)

parent b925093e
...@@ -2,10 +2,18 @@ import json ...@@ -2,10 +2,18 @@ import json
import sys import sys
from collections import OrderedDict from collections import OrderedDict
f = sys.stdin import argparse
if len(sys.argv) > 1:
f = open(sys.argv[1]) parser = argparse.ArgumentParser(description = 'Format a .json file')
s = parser.add_argument('--unsorted', '-u', action='store_true', help='do not sort the file (%(default)s)')
print json.dumps(OrderedDict(json.loads(s, object_pairs_hook=OrderedDict))).replace('\n', ' ') parser.add_argument('--one-line', '-1', action='store_true', help='one line output (%(default)d)')
parser.add_argument('file', nargs='?', type=argparse.FileType('r'), default=sys.stdin, help='.json file')
args = parser.parse_args()
json_data =
print json.dumps(json.loads(json_data, object_pairs_hook=OrderedDict),
sort_keys=not args.unsorted,
indent=None if args.one_line else 2)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment