File size: 549 Bytes
df08103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import yaml
import glob

# convert yaml to json
def yaml_to_json(yaml_file):
    with open(yaml_file) as f:
        data = yaml.safe_load(f)
    # return data
    basename = yaml_file.split(".")[0]
    # save json data to a file
    with open(f"{basename}.json", "w") as f:
        # utf-8 encoding
        f.write(json.dumps(data, indent=4, ensure_ascii=False))

    return data


if __name__ == "__main__":
    # yaml_file = "test.yaml"
    # yaml_to_json(yaml_file)

    for f in glob.glob("config/*/*.yaml"):
        yaml_to_json(f)