Spaces:
Sleeping
Sleeping
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) | |