]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/json/tool.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / json / tool.py
CommitLineData
4710c53d 1r"""Command-line tool to validate and pretty-print JSON\r
2\r
3Usage::\r
4\r
5 $ echo '{"json":"obj"}' | python -m json.tool\r
6 {\r
7 "json": "obj"\r
8 }\r
9 $ echo '{ 1.2:3.4}' | python -m json.tool\r
10 Expecting property name: line 1 column 2 (char 2)\r
11\r
12"""\r
13import sys\r
14import json\r
15\r
16def main():\r
17 if len(sys.argv) == 1:\r
18 infile = sys.stdin\r
19 outfile = sys.stdout\r
20 elif len(sys.argv) == 2:\r
21 infile = open(sys.argv[1], 'rb')\r
22 outfile = sys.stdout\r
23 elif len(sys.argv) == 3:\r
24 infile = open(sys.argv[1], 'rb')\r
25 outfile = open(sys.argv[2], 'wb')\r
26 else:\r
27 raise SystemExit(sys.argv[0] + " [infile [outfile]]")\r
28 try:\r
29 obj = json.load(infile)\r
30 except ValueError, e:\r
31 raise SystemExit(e)\r
32 json.dump(obj, outfile, sort_keys=True, indent=4)\r
33 outfile.write('\n')\r
34\r
35\r
36if __name__ == '__main__':\r
37 main()\r