What is JSON?

At some point in history, XML was the most popular choice for data exchange. However, after the rise of web applications and JavaScript. JSON was developed and became the main choice for data exchange.

JSON (JavaScript Object Notation) is a minimal, human-readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML. 

JSON has several advantages:

  • It is very compact 
  • It is easily readable for applications and people
  • It is easily mapped into most programming languages' data structures
  • All programming languages have libraries that can read and wire JSON
  • It is just plain text, thus it is easy to send and receive over the network and is language independent

JSON vs XML

Nowadays, both JSON and XML are widely used. Let’s have a look at the differences between the two:

JSON XML
JSON has a more compact style as compared to XML. XML is less readable compared to JSON and becomes hard to manage in large files.
JSON supports arrays. XML doesn't support arrays.
JSON is more human-readable XML is less human-readable.
JSON supports only text and number data types XML support many data types including images, graphs, etc.

Let's look at the following example to understand why JSON is more human-readable than XML:

XML Example:

<interfaces>
<interface>
<name>Gig0/0</name>
<address>10.1.1.1</address>
</interface>
<interface>
<name>Gig0/1</name>
<address>10.5.1.1</address>
</interface>
<interface>
<name>Gig0/2</name>
<address>10.8.5.1</address>
</interface>
</interfaces>

JSON Example:

{"interfaces":[
{"name":"Gig0/0", "add":"10.1.1.1"},
{"name":"Gig0/1", "add":"10.5.1.1"},
{"name":"Gig0/2", "add":"10.8.5.1"}
]}

What is JSON used for?

JSON is most widely used for sending and receiving data between web applications. Very common day-to-day usage of JSON is when a browser exchange data with a web server using a technology called AJAX

In Networking, most platforms that have a programming interface API, accept and return HTTP messages that contain JavaScript Object Notation (JSON). Payloads to and from the API interface can be encapsulated through either XML or JSON encoding.