JSON vs XML

Kesavi Kanesalingam
3 min readApr 19, 2020

First we will understand what is JSON and what is XML.

JSON is used to store information in an organized, and easy-to-access manner. Its full form is JavaScript Object Notation. It offers a human-readable collection of data which can be accessed logically.

XML is a markup language which is designed to store data. It’s popularly used or transfer of data. It is case sensitive. XML offers you to define markup elements and generate customized markup language. The basic unit in the XML is known as an element. Extension of XML file is .xml

Features of JSON

  • Light-weight : When working with AJAX, it is important to load the data quickly and asynchronously without requesting the page re-load. Since JSON is light weighted, it becomes easier to get and load the requested data quickly.
  • Easy to read and write : JSON objects are having a standard structure that makes developers job easy to read and write code, because they know what to expect from JSON.
  • Performance : JSON is quite fast as it consumes very less memory space, which is especially suitable for large object graphs or systems.
  • Free tool : JSON library is open source and free to use.
  • Doesn’t require to create mapping : Jackson API provides default mapping for many objects to be serialized.
  • Clean JSON : Creates clean, and compatible JSON result that is easy to read.
  • Dependency : JSON library does not require any other library for processing.

Features of XML

  • Excellent for handling data with a complex structure or atypical data
  • Data described using markup language
  • Text data description
  • Human- and computer-friendly format
  • Handles data in a tree structure having one-and only one-root element
  • Excellent for long-term data storage and data reusability.
  • XML tags are not predefined. You need to define your customized tags.
  • XML was designed to carry data, not allows you to display that data.
  • Mark-up code of XML is easy to understand for a human.
  • Well, the structured format is easy to read and write from programs.
  • XML is an extensible markup language like HTML.

Similarities between JSON and XML

  • Both are simple and open.
  • Both are “self describing” (human readable).
  • Both supports unicode.
  • Both are interoperable or language-independent.
  • Both are hierarchical (values within values).
  • Both can be parsed and used by lots of programming languages.
  • Both can be fetched with an XMLHttpRequest.

Difference between JSON and XML

Example For JSON

{
"student": [

{
"id":"01",
"firstname": "Smith",
"lastname": "John"
},

{
"id":"02",
"firstname": "Peter",
"lastname": "Steve"
}
]
}

Example for XML

<?xml version="1.0" encoding="UTF-8" ?>
<root>
<student>
<id>01</id>
<firstname>Smith</firstname>
<lastname>John</lastname>
</student>
<student>
<id>02</id>
<firstname>Peter</firstname>
<lastname>Steve</lastname>
</student>
</root>

Why JSON is better than XML

  • Less verbose
  • Faster
  • Readable
  • Structure matches the Data
  • Objects Align in Code
  • JSON is parsed into a ready-to-use JavaScript object.
  • Easy to create and manipulate

Why XML is better than JSON

  • More secure
  • Makes documents transportable across systems and applications. With the help of XML, you can exchange data quickly between different platforms.
  • XML separates the data from HTML
  • XML simplifies platform change process
  • XML supports namespaces and comments.
  • XML is supported by many more desktop applications than JSON.

--

--