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.
Table of Contents
In this YAML example, you can see that there is an equal number of white spaces in each block.
{ "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 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>
Now many find it difficult which data serialization language should be used for project development.
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.
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.
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.
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.
Great job.
Thanks, Siva! Glad as you find it useful.
I was in confusion to learn one of these formatting languages. Thank you. Helpful information.
You’re welcome, Sriram. Hope you made your choice.
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.
YAML;
—
A good introduction to YAML with a comparison to XML and JSON. Recently I began to use AWS where YAML is widely used
Good to know that Alex. What technical stack you are using on AWS?
There is a better format – tree.
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.
Well. You got the point. Thanks for sharing your thoughts. Beneficial for our enthusiastic readers.
So nicely said, appreciated it!!!