DevOps Prerequisite (Part 7): YAML & Json
Tags: devops
Published: 2023-03-25 08:53:03

This is how YAML file looks:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lhekhr786hcqpe32ms9f.png)
 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2zr8pc9gp1chs0vtyovq.png)
Dictionaries 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/307vqa031pshcmuiz2a7.png)
Moreover, order matters in list but it does not matter in dictionary

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z1c6xgqa60hsxi1s3wcq.png)

[Take this quiz](https://kodekloudhub.github.io/yaml-quiz/index.html)

**Json and Json Path**

In Json, things are bit different. Using brackets like 2nd bracket and third one.

Here you can see yaml used spaces and json used "{}"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qh5imgij6ypdze682t5f.png)
For lists, yaml uses "-" where as json uses "[]"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4mll15of20791lvj4xe6.png)

Use this [Json to Yaml converter](https://www.json2yaml.com/)
**Json Path**

Query language applied in json or yaml format.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0kkm724s5gsruymfcdxx.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1d77027d1zdnbm345nx.png)

If there is no dictionary mentioned, it means root dictionary and we use $ in json path to mean that.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h58ep1tylv3hk1j0yo6c.png)
The results will be in square brackets.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0cf44riyonkq5ampp505.png)

This is how we use indexing here.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/17xvdfzpdzppirsjppk9.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m13m7aa8vrysoxfydmp3.png)
We can also find numbers greater than 40 by this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ig4x8j9mzogl97iunr59.png)

Here ? means check if
@ means each item and others are conditions like (> , ! etc)

We could also filter car models using their locations by this

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wtbew8vzxjlun2saz3to.png)

here, @.location means checking each item's(index 0,1,2,3) location and then if they find a value of rear-right in any location, that is the desired item.
Here our desired item is index 1 and then we get the value of the model.

[Take part in the labs](https://mmumshad.github.io/json-path-quiz/index.html)
Just like this...
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rkn5a3kdmh0gihtw79vc.png)
After successfully completing these,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jwlnm0kd7bzhk6m9phul.png)

You can also do a free course from [KodeKloud](https://kodekloud.com/lessons/lesson-14/)

<img src="https://media0.giphy.com/media/Nfs5y1kzJKfu/giphy.gif?cid=ecf05e472d3w835ptrri5m1p6ifnwl9mi7ope9pifvhpcxf6&rid=giphy.gif&ct=g">