Creating a Dictionary in Python and writing it to json file
import json
cloud_providers = {'Google': "GCP", 'Amazon': "AWS", 'Micrososft': "Azure"}
data = json.dumps(cloud_providers)
print(data)
with open("cloud_providers.json", "w") as f:
f.write(data)
f.close()
Read a json file services.json kept in this folder and print the service names of every cloud service provider.
import json
json_file = open('F:/VS CODE/day15_task/Devops-Challenge/2023/day15/services.json', 'r')
data = json_file.read()
services = json.loads(data)
key_list = list(services['services'].keys())
for i in range(1,len(key_list)):
print(key_list[i],":",services['services'][key_list[i]]['name'])
Read YAML file using python, file services.yaml and read the contents to convert yaml to json
import yaml
import json
input_file = open('F:/VS CODE/day15_task/Devops-Challenge/2023/day15/services.yaml','r')
yaml_data = input_file.read()
yaml_file = yaml.safe_load(yaml_data)
print(type(yaml_file))
json_file = json.dumps(yaml_file)
with open("new_services.json",'w') as f:
f.write(json_file)
f.close()