1 | #!/usr/bin/env python2
|
2 | """
|
3 | yaml2json.py
|
4 |
|
5 | Note: this tool is incorrect! See 'bug' in yaml2json.sh.
|
6 |
|
7 | https://john-millikin.com/json-is-not-a-yaml-subset
|
8 | """
|
9 | from __future__ import print_function
|
10 |
|
11 | import json
|
12 | import sys
|
13 |
|
14 | import yaml
|
15 |
|
16 |
|
17 | def main(argv):
|
18 | argv = argv[1:]
|
19 |
|
20 | if len(argv) == 0:
|
21 | obj = yaml.safe_load(sys.stdin)
|
22 |
|
23 | elif len(argv) == 1:
|
24 | with open(argv[0]) as f:
|
25 | obj = yaml.safe_load(f)
|
26 |
|
27 | else:
|
28 | raise RuntimeError('Too many args')
|
29 |
|
30 | json.dump(obj, sys.stdout, indent=2)
|
31 |
|
32 |
|
33 | if __name__ == '__main__':
|
34 | try:
|
35 | main(sys.argv)
|
36 | except RuntimeError as e:
|
37 | print('FATAL: %s' % e, file=sys.stderr)
|
38 | sys.exit(1)
|