# #Devops Day15

Hello, Everyone, This is my 15 blog started my day15 as AWS DevOps Engineer #90daysofchallenge with ShubhamLondhe #devops #trainwithshubham.

### Python Libraries for DevOps

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707319726234/c871bc89-36cc-4053-9379-e46b75b6daba.png align="center")

### Reading JSON and YAML in Python

* As a DevOps Engineer you should be able to parse files, be it txt, json, Yaml, etc.
    
* You should know what all libraries one should use in Python for DevOps.
    
* Python has numerous libraries like `Os`, `sys`, `json`, `yaml` etc that a DevOps Engineer uses in day to day tasks.
    

### **Task 1: Create a Dictionary in Python and write it to a JSON File:**

**JSON (JavaScript Object Notation):**

**\-&gt;Library:** json

**\-&gt;Purpose:** Used for encoding and decoding JSON data.

**\-&gt;Functions:**

\-&gt; json.dumps(): Serialize Python data to a JSON formatted str.

\-&gt; json.dump() Write a Python object in JSON format to a file.

\-&gt; json.loads(): Deserialize a JSON document to a Python object.

\-&gt; json.load(): Read a file containing a JSON document and convert it to a Python object.

**Example:**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707319187258/7705b4f9-f6da-4007-a947-cf75850caaed.png align="center")

After running this code, a file named 'devOps.json' will be created in the same directory, containing the JSON representation of the DevOps dictionary. The file content will look like this:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707319238606/e2e4d539-ef16-43f6-83c5-5c623fa74a0f.png align="center")

### **Task 2: Read a json file service.json kept in this folder and print the service names of every cloud service provider.**

Certainly! To achieve this, you can use the json module in Python. Here's a simple example:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707319379108/df581a14-476e-49ee-b66a-7df3fda197e6.png align="center")

it produce the desired output:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707319441244/dbe6a27d-6197-4c83-9850-d6b7384cf6c2.png align="center")

### **Task 3: Read YAML file using python, file service.yaml and read the contents to convert yaml to json:**

To read a YAML file using Python and convert its contents to JSON, you can use the `PyYAML` library to handle YAML parsing. Make sure to install the library first:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707319492792/ec588b4c-780f-4945-bc14-4b2e62ece775.png align="center")

Now, you can use the following Python code:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707319594258/a696341b-a4f7-4ede-a8f9-1dc4722c33bf.png align="center")
