YAML vs JSON vs XML | What is the Difference Between Them?

YAML vs JSON vs XML | What is the Difference Between Them?

YAML, XML, and JSON are the widely used data serialization language. In this post, I will list out the difference Difference Between YAML and JSON and XML.

You may be well known about XML and JSON. You can read my earlier post, where I have talked detail about YAML, advantages, and disadvantages of YAML.

Now, let’s start pondering on the difference between YAML and JSON and XML. At the end of this post, I will also help you to choose the most suitable data serialization language for your next project.

YAML vs JSON vs XML

  • YAML stands for “YAML Aint Markup Language“.
  • JSON stands for “JavaScript Object Notation“.
  • XML is “eXtensible Markup Language” whereas YML is not a markup language.
  • XML uses a tag to define the structure just like HTML.
  • YAML uses indentation to define structured data. So each block in the YAML is differentiated by the number of white spaces.
  • All three mentioned serialization language has same extension as their name. (.yaml for YAML, .json for JSON, .xml for XML). So it is easy to remember.
  • In fact, file extensions are arbitrary for all the three data serialization standard. It is useful for the application and users to know what files format, type of the content and their data structure.

YAML Example

In this YAML example, you can see that there is an equal number of white spaces in each block.

Advantages of YAML over XML and JSON

JSON Example

{
"EmpRecord": {
"Employee": [
{
"-id": "emp01",
"name": "Alex",
"job": "Developer",
"skills": "python, C/C++, paskal"
},
{
"-id": "emp02",
"name": "Bob",
"job": "Tester",
"skills": "lips, forton, REST APIs"
}
]
}
}

XML Example


<?xml version="1.0"?>
<EmpRecord>
<Employee id="emp01">
<name>Alex</name>
<job>Developer</job>
<skills>python, C/C++, paskal</skills>
</Employee>

<Employee id="emp02">
<name>Bob</name>
<job>Tester</job>
<skills>lips, forton, REST APIs</skills>
</Employee>

</EmpRecord>

Differentiating YAML vs JSON vs XML by its Applications

Now many find it difficult which data serialization language should be used for project development.

  • When you talk about Javascript, JSON is the most prominent serialization language.
  • For Java programming, you must have seen XML is widely used.
  • Python has the same indentation technique same as YAML. So Pythonista finds YAML more friendly than other serialization languages.

Ad on to all above points regarding the programming preference. It does not hold true always. If you want to use data serialization language, you should also consider developing techniques for your project.

Differentiating YAML, JSON and XML according to the project need

Q: How should I choose the data serialization language for my next project?

Data is represented in serialization language(YAML/JSON/XML) which is well structured. Using any of the serialization languages, consist of four major activities.

  • You need to parse the content from this serialization language.
  • Read the required values.
  • Manipulate those values.
  • Further, you may need to store manipulated values back serialization language file.

To do all these development activities, you have to write the code for parsing.

Fortunately, there are so many modules/libraries or open-source code in various core languages (like C, C++, Java…) to parse serialized data.

Q: Why should not you waste your time writing YAML/JSON/XML parser?

There can be some mistakes if you develop it by yourself. It’s recommended/good to use prominent existing libraries. It also saves your time.

So before using serialization language in your project; research, find parsing libraries, read documents. Find compatibility of the parser to use in your project.

If you get the parsing libraries as per your requirement, you have almost curated all data handling activities. Isn’t it easy to call simple one function to parse values rather than parsing it manually?

So for the programmer, it is easy to choose YAML vs JSON vs XML by the availability of the data parser.

Q: Why did I choose JSON with Python?

This is for Python programming. I am putting my own thought being haughty Python developer.

I worked on one of the Redfish projects which is built on the REST API and bottle framework. The core language we used is Python. We had a requirement to transfer data between client and server. When we were looking for serialization language for data transfer, we choose JSON. You can see there is already JSON parsing libraries in Python (like many other serialization languages).

There is also one of the most prominent reasons using JSON with Python. Python Dictionary and any serialization language are nothing but the code to store name-value pair data. If you look into the Python dictionary and JSON data format, JSON maps format is pretty much similar to the Python dictionary.

Final Thought

This is all about YAML vs JSON vs XML. Hope this will help you to find the difference between YAML and JSON and XML.

Also Read: 5 Simplest Programming Languages for Beginners

If you are differentiating any of the data serialization languages, it’s all about data representation format. We can not underestimate one serialization language to others. Each of these data serialization standards has its comfortability with different core programming languages. More ever it’s all about the developer how do they feel comfortable over understanding and parsing serialization languages.

So did you find the most suitable data serialization language for your project? Still not? Write your query in the comment. I will reply as soon as possible.

11 Comments

  1. Your examples should be the same, but they are not. i.e. in YAML, the skills is an array while in the others it’s a simple string.

    JSON:
    {
      "EmpRecord": {
        "emp01": {
          "name": "Alex",
          "job": "Developer",
          "skills": "python, C/C++, paskal"
        },
        "emp02": {
          "name": "Bob",
          "job": "Tester",
          "skills": "lips, forton, REST APIs"
        }
      }
    }
    

    YAML;

    EmpRecord:  
      emp01:
        name: Alex
        job: Developer
        skills: python, C/C++, paskal
      emp02:
        name: Bob
        job: Tester
        skills: lips, forton, REST APIs
    
  2. The main benefit of YAML is readability and editability. JSON and XML are messy and hard to visually parse. I’m leaning toward using YAML everywhere human hands may read or touch, and converting on the fly to JSON or XML where machines are talking to one another.

Leave a Reply

Your email address will not be published. Required fields are marked *