-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyaml2json.py
executable file
·40 lines (30 loc) · 974 Bytes
/
yaml2json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#! /usr/bin/env python
#coding:utf8
"""
Author: tao peng --<[email protected]>
Purpose:
1. 将yaml配置文件转化为json。当前线上php没有yaml的extension。折中办法。
History:
1. 2014/6/18 15:40 : yaml2json.py is created.
"""
from argparse import ArgumentParser
import json
import yaml
#----------------------------------------------------------------------
def parse_args():
"""
"""
parser = ArgumentParser(description='convert yaml file to json.')
parser.add_argument("input", metavar='INPUT', help="input yaml file name.")
parser.add_argument("output", metavar='OUTPUT', help="output json file name.")
args = parser.parse_args()
return args
#----------------------------------------------------------------------
def main(args):
"""
"""
obj = yaml.load(open(args.input))
json.dump(obj, open(args.output, "w"), indent=4)
if __name__=='__main__':
args = parse_args()
main(args)