def generate_json_files(config_path, template_path):
with open(template_path, 'r') as file:
template = json.load(file)
with open(config_path, 'r') as file:
config = yaml.safe_load(file)
with open(config_path, 'r') as file:
config = yaml.safe_load(file)
for key, values in config.items():
for i, value in enumerate(values):
json_data = template.copy()
current_data = json_data
keys = key.split('.')
for j, k in enumerate(keys):
if j == len(keys) - 1:
current_data[k] = value
else:
if k not in current_data:
current_data[k] = {}
current_data = current_data[k]
with open(f'{key}_{i}.json', 'w') as file:
json.dump(json_data, file, indent=4)
generate_json_files('example.yaml', 'template.json')