Python DevOps Magic: Easy JSON & YAML Handling โจ๐ Day - 15
๐ Hello, I'm Vishal, an aspiring Information Technology enthusiast currently embarking on a journey towards a Bachelor's degree in Engineering. My passion lies in exploring the dynamic realms of cloud computing and DevOps technologies, where I constantly strive to bridge the gap between innovation and practical implementation.
๐ก As a student of Information Technology, I'm on a mission to absorb knowledge, solve real-world problems, and contribute to the tech community. My academic pursuits fuel my curiosity, and my hands-on experience with cloud and DevOps tools empowers me to navigate the evolving landscape of modern technology.
๐ Join me as I share insights, discoveries, and challenges encountered on this exciting educational and professional adventure. Let's connect, collaborate, and grow together in the ever-expanding world of IT.
๐ Connect with me on social media and let's build a network that fosters learning, sharing, and innovation.
Happy coding! ๐
Hello DevOps enthusiasts! ๐ Today, let's explore the simplicity that Python brings to our daily DevOps tasks, specifically when it comes to working with JSON and YAML files.
Crafting Cloud Chronicles with Python Magic
Creating a JSON file for your cloud services is as easy as brewing your favorite potion:
import json
# Cloud services potion
cloud_services = {
"aws": "ec2",
"azure": "VM",
"gcp": "compute engine"
}
# Save it to 'services.json'
with open("services.json", "w") as json_file:
json.dump(cloud_services, json_file)
Your cloud services saga is now chronicled in 'services.json'.
Deciphering Cloud Service Scrolls
Reading and revealing the cloud service names is like reading from an ancient scroll:
# Read the scroll in 'services.json'
with open("services.json", "r") as json_file:
data = json.load(json_file)
# Unveil the services
for provider, service in data.items():
print(f"{provider} : {service}")
The magic output appears:
aws : ec2
azure : VM
gcp : compute engine
Python's Alchemy on YAML Chronicles
Transforming YAML into JSON is a gentle wave of the wand:
import yaml
import json
# Read the YAML spellbook
with open("services.yaml", "r") as yaml_file:
yaml_data = yaml.safe_load(yaml_file)
# Witness the seamless transformation
json_data = json.dumps(yaml_data, indent=2)
print(json_data)
And just like that, Python transmutes YAML into JSON effortlessly.
In the realm of DevOps, Python is your friendly guide, making JSON and YAML handling a piece of cake. Join the simplicity and make your DevOps journey a delightful experience! โจ๐
Happy coding! ๐ป๐


