Nowadays, almost every person is familiar with the standard format of JSON. Contrarily, individuals who use Docker are surely familiar with YAML. In simpler words, Docker is a toolkit which permits developers to run, build, deploy, modify as well as stop packages through a single API or commands. YAML is a new but popular language used to serialize data. First of all, we should perceive what data serialization is. Data serialization is the most common way of transforming data objects into byte streams used to store, transfer and distribute data on devices. However, they have similar objectives to store structures and data objects into files but distinctive ways to work.
In this article, we first go through the features of JSON and YAML, then compare them in-depth to completely comprehend their advantages, and then briefly discuss which one is better.
YAML is an abbreviation of Yet Another Markup Language and is used to define configurations. It is lightweight and represents data in a human-readable format. If you want to parse JSON then you have to use the YAML parser as JSON is a subset of YAML. Moreover, JSON can be converted into YAML. YAML also has JSON in its configuration files. YAML not only permits user-defined data types but also allows explicit data typing. “.YML” or “.YAML” are extensions of YAML. Here is the link to its official documentation https://yaml.org/. YAML differs from JSON as it uses Python-like indentations to represent levels in data. In YAML, lists start with hyphens and key pairs can be separated with a colon. Three dashes (“—”) indicate the beginning of a document whereas three dots (“…”) indicate the end of a document.
Below is the example to show the YAML format. This example contains information about various cars.
List of Cars:
- car registration number: 011
car name: Civic
owner of car: Zaim Khan
model number: xyz
price: 20 lacs
- car registration number: 012
car name: Mehran
owner of car: Sara Khan
model number: xyzasd21
price: 10 lacs
- car registration number: 013
car name: Cultus
owner of car: Taimur Ali
model number: xy12z
price: 15 lacs
Below is the example to show the JSON format. This example stores information related to cars.
"List of Cars" : [
"car registration number":"011",
"owner of car":"Zaim Khan",
"car registration number":"012",
"owner of car":"Sara Khan",
"car registration number":"013",
"owner of car":"Taimur Ali",
YAML VS JSON:
YAML and JSON are not as simple to compare as you think. If we talk about the readability of data from configuration files then both JSON and YAML can be used interchangeably. Therefore, the comparison is quite difficult in terms of readability. In the configuration file, JSON might be able to express the same data types just like YAML. Although YAML is a set of key/value pairs, there is no object in it.
In JSON, strings can be used in double-quotes whereas YAML supports both single and double-quotes. Comments are not allowed in JSON while comments are represented through hash or number signs in YAML.
It is quite difficult to decide whether JSON is better or YAML. Therefore, I have decided to compare these with different aspects. When you talk about readability, YAML is much better, but moving towards the size then JSON takes the edge. JSON is comparatively faster than YAML. However, if data configurations are small then YAML is better since its interface is much more friendly.
JSON has a feature to encode six different data types like an object, array, strings, numbers, null and boolean. JSON is much easier for machines to parse and it is quite flexible compared to YAML which allows encoding of python data but with vulnerabilities while decoding. That’s why YAML is too hard to parse.