PermalinkTask-1 - Create a Dictionary in Python and write it to a JSON File:
Step-1 create a file name create_dict.py
touch create_dict.py
Here I have written a file into it and will import it into JSON File :
import json
my_dict = {
"name": "John",
"age": 30,
"city": "New York"
}
with open("my_dict.json", "w") as file:
json.dump(my_dict, file)
Step-2 Create a json file by running this python file and verify with the command "ls"
python3 create_dict.py
Step-3 Verify it :
vi my_dict.json
PermalinkTask-2 - Read a json file services.json
kept in this folder and print the service names of every cloud service provider.
Step-1 Create a file services.json and write the following code into it :
[
{
"name": "aws",
"services": "ec2"
},
{
"name": "azure",
"services": "VM"
},
{
"name": "gcp",
"services": "compute engine"
}
]
Step-2 Create a new file named Cloud_services.py and write the following code into it
import json
# Read the JSON data from the file
with open('services.json') as f:
data = json.load(f)
# Print the service names for each cloud service provider
for provider in data:
print(provider['name'], ':', provider['services'])
Step-3 Now run it with python it will revert the content:
python3 cloud_services.py
\=========================THANK YOU==========================