# JSON, XML, & YAML

**Data serialization** is the process of converting data into a serialized format/structure that can be stored or transmitted and reconstructed later. This allows the data to be communicated between applications in a way both applications understand. Data serialization languages allow us to represent variables with text. **Variables** are containers that store values.&#x20;

<figure><img src="https://3642595937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsHxwINrQaKCeVpC90i9%2Fuploads%2FDZ3S0lC0lOIwoEB1TZ0D%2Fimage.png?alt=media&#x26;token=e159f7fa-888e-43f4-ab04-5c704406a6d7" alt="data serialization demo" width="563"><figcaption></figcaption></figure>

### JSON

**JSON** (JavaScript Object Notation) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects. REST APIs often use JSON. In JSON, whitespace is insignificant.

JSON primitive data types:

* **String** - a text value. It is surrounded by double quotes (`" "`).
* **Number** - a numeric value.&#x20;
* **Boolean** - data type that has only two possible values (true or false).
* **Null** - represents the intentional absence of any object value (`null`).

JSON structured data types:

* **Object** - an unordered list of key-value pairs (variables). Objects are surrounded by curly brackets (`{}`). The **key** is a string and the **value** is any valid JSON data type. The key and value are separated by a colon (`:`). If there are multiple key-value pairs, each pair is separated by a comma (`,`). Objects within objects are called **nested objects**.<br>

  <figure><img src="https://3642595937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsHxwINrQaKCeVpC90i9%2Fuploads%2FoXlKwTqaR8jWu5JGyxKx%2Fimage.png?alt=media&#x26;token=f6d6ed20-6175-4265-927b-bac85995262c" alt="object example" width="563"><figcaption></figcaption></figure>
* **Array** - series of values separated by commas. The values don't have to be the same data type.<br>

  <figure><img src="https://3642595937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsHxwINrQaKCeVpC90i9%2Fuploads%2FGOi6w8rar2EON3qK0V3s%2Fimage.png?alt=media&#x26;token=0ebeb7a0-1591-4304-ba49-21b944c964b3" alt="array example" width="563"><figcaption></figcaption></figure>

### XML

**XML** (Extensible Markup Language) was developed as a markup language but is now used as a general data serialization language. Markup languages are used to format text. XML is less human-readable than JSON. The whitespace is insignificant. Used by REST APIs.

<figure><img src="https://3642595937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsHxwINrQaKCeVpC90i9%2Fuploads%2FB3I2iEHtBiFKGcfIyOcY%2Fimage.png?alt=media&#x26;token=a50da708-1bc7-4a89-a9bc-527d680c0261" alt="XML example" width="563"><figcaption></figcaption></figure>

### YAML

**YAML** originally meant Yet Another Markup Language but to distinguish its purpose as a data-serialization language rather than a markup language, it was repurposed to YAML Aint Markup Language. It is used by the network automation tool Ansible. It is very human-readable. Whitespace is significant, indentation is very important. YAML files start with `---`. `-` is used to indicate a list. Keys and values are represented as `key:value`.

<figure><img src="https://3642595937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsHxwINrQaKCeVpC90i9%2Fuploads%2FWJXe0vfdDg0soePLhWKe%2Fimage.png?alt=media&#x26;token=df69ec11-acf1-4c7b-b290-93f1cf1d9828" alt="YAML example" width="563"><figcaption></figcaption></figure>

{% file src="<https://3642595937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsHxwINrQaKCeVpC90i9%2Fuploads%2FPz0iR9J5poLvqEC3Dpin%2FDay%2060%20Flashcards%20-%20JSON%2C%20XML%2C%20_%20YAML.apkg?alt=media&token=e956afca-9cb5-442f-a716-dfd12c2d3e76>" %}
