XML vs JSON - The Coding Shala

Home >> CS Fundamentals >> XML vs JSON

 In this post, we will learn the basic difference between XML and JSON.


XML and JSON are the most popular formats of data that can be understood both by computers and by humans. These formats are used to exchange information between servers, between various components in a single application, and much more.


  • XML stands for eXtensible Markup Language.
  • XML uses tags to hold data. Everything in XML is built on tags.
  • A tag is a specially-formatted label used in markup languages: <opening_tag>content</closing tag>.
  • XML is used for storing and transporting data.
  • XML contains data in a hierarchical order.
Example of XML:


    <book category="some categoty">
        <title lang="en">Everyday Italian</title>
        <author>Gaida De Laurentis</author>

An XML document can be stored on the computer with a .xml extension. Each XML document consists of tags and elements. The first line in the XML document is called a prologue (<?xml version="1.0" encoding="UTF-8"?>).

XML elements can possess attributes that provide additional information about the element. The value of the attribute is always set in either double or single quotes. For example, the name of a picture can be written as follows:

<picture name="The Black Square"/>

Pros and cons of XML

  • It can be easily understood by machines and people alike.
  • The format is based on international standards.
  • It has a well-defined structure that facilitates the search and extraction of information.
  • Modern programming languages have libraries for processing XML documents automatically.
  • At the same time, XML has an important disadvantage. Its redundant syntax causes higher storage and transportation cost. It is especially important when we need to store or transfer a large amount of data.


  • JSON stands for JavaScript Object Notation.
  • JSON is a very flexible format. It has arrays, objects, strings, numbers, booleans, and null. 
  • JSON (or JavaScript Object Notation) is a text-based format for storing and transmitting structured data. It comes from the JavaScript language, but it is still considered to be language-independent: it works with almost any programming language. With JSON's lightweight syntax, you can easily store and send to other apps everything from numbers and strings to arrays and objects. You can also create more complex data structures by linking arrays to each other.
Example of JSON:

    "id" : "67533566",
    "number" : "8-900-000-00-04",
    "date" : "2018-12-15",
    "amount" : "5000.00"

Advantages of JSON
  • JSON is widely spread for data exchange on the Internet because of its strong advantages in compactness, flexibility, and high readability, even for people far from programming.
  • Most programming languages have functions and libraries for reading and creating JSON structures.
  • The JSON is a general format to pass structured data through the network because after you serialize data to JSON, you can deserialize it back without losing any information. The main advantage of JSON comparing to plain text is the ability to describe relations between objects via nesting and key-value pairs. So, it's high chances that the sites you're often visiting use JSON too.

Other Posts You May Like
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.


Popular Posts from this Blog

Add two numbers in Scala - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

Goal Parser Interpretation LeetCode Solution - The Coding Shala

Maximum Population Year LeetCode Solution - The Coding Shala

Shell Script to find sum, product and average of given numbers - The Coding Shala