2 # -*- coding: utf-8 -*-
4 """jsonfmt.py - JSON formatter
6 File ID: 423dd854-4a64-11e4-97b1-c80aa9e67bbd
7 License: GNU General Public License version 2 or later.
8 Author: Øyvind A. Holm <sunny@sunbase.org>
13 def format_json(text
, indent
=2, sort
=False):
14 """Return formatted JSON"""
30 progname
= os
.path
.basename(__file__
)
32 parser
= argparse
.ArgumentParser(
33 description
="JSON formatter",
39 help="Use X spaces as indent",
48 help="Sort JSON elements alphabetically",
50 args
= parser
.parse_args()
55 "".join(sys
.stdin
.readlines()),
61 sys
.stderr
.write("%s: Invalid JSON\n" % progname
)
64 if __name__
== "__main__":