import yaml
import json
import os
def yaml2json(input='./config.yaml', output='./config.json'):
input = os.path.abspath(input)
output = os.path.abspath(output)
with open(input, encoding='utf-8') as y:
conf = yaml.load(y, Loader=yaml.FullLoader)
with open(output, 'w', encoding='utf-8') as j:
j.write(json.dumps(conf, ensure_ascii=False, indent=2))
def json2yaml(input='./config.json', output='./config.yaml'):
input = os.path.abspath(input)
output = os.path.abspath(output)
with open(input, encoding='utf-8') as j:
conf = json.load(j)
with open(output, 'w', encoding='utf-8') as y:
y.write(yaml.dump(conf, sort_keys=False, allow_unicode=True))
if __name__ == '__main__':
#yaml2json()
json2yaml()