XML and JSON Data Formats

Applications use APIs to exchange data. Since different applications save data in separate formats, the API must convert the data into a format that both the sending and receiving applications understand. The process of converting data into a generic format is called data serialization. XML and JSON are data serialization languages.

XML data format

Web pages use HTML (Hypertext Markup Language). HTML is a static language. It defines how to add text or a web page to a file and then incorporate additional text, known as markup, to denote formatting details for the text displayed in the browser. For example, the markup included codes for headings, paragraphs, font types, sizes, colors, hyperlinks, etc.

XML (eXtensible Markup Language) makes web pages dynamic. It is a markup and data serialization language. It has many features to define variables, values, and data structures. It uses beginning and ending tags for each variable. For instance, in the following example, <interfaceCount> and </interfaceCount> are tags. They denote a variable name, with the value (24) sitting between the tags.

<?xml version = "1.0" encoding = "UTF-8"?>
<root>
  <response>
    <family>Switches and Hubs</family>
    <hostname>cat_4k_2</hostname>
    <interfaceCount>24</interfaceCount>
    <lineCardCount>4</lineCardCount>
    <macAddress>48:5b:20:67:32:80</macAddress>
    <managementIpAddress>20.20.20.2</managementIpAddress>
    <role>ACCESS</role>
    <serialNumber>FCC2146L0AK</serialNumber>
    <series>Cisco Catalyst 2400 Series Switches</series>
    <softwareType>IOS-XE</softwareType>
    <softwareVersion>12.6.1</softwareVersion>
    <type>Cisco Catalyst 2400 Switch</type>
    <upTime>17 days, 12:35:08.12</upTime>
  </response>
</root>

JSON data format

XML adds an opening and closing tag with each variable. It increases the amount of data to be exchanged. As mobile applications became popular, there was a need for a new data format to reduce the amount of data transmitted, especially over cellular phone networks. Besides increasing the amount of data, opening and closing tags with every variable makes XML a complex language. JSON (JavaScript Object Notation) solves both issues. It uses fewer tags and formats data in a more human-readable format. It is considered a lightweight data exchange protocol compared to XML.

JSON data format example

{
"R1": ["GigabitEthernet0/0", "GigabitEthernet0/1"],
"R2": ["GigabitEthernet1/0", "GigabitEthernet1/1"],
"R3": ["GigabitEthernet1/0", "GigabitEthernet1/1"]
}

Interpreting JSON data

JSON uses key:value pairs to format data. The key is the name of an individual variable. The value is the variable's value. To separate the key from its value, it uses a colon. It keeps the key before the colon and the value after the colon.

json data format

To denote a single JSON object, it uses curly brackets. The curly brackets that begin and end the JSON data represent a single JSON object. If a JSON object has multiple key:value pairs, it uses a comma to separate them. If a key:value pair ends with a comma, it means another key:value pair will follow it. If a key:value pair ends without a comma, it means it is the last key:value pair in the object.

Conclusion

XML and JSON serve as essential data serialization languages that facilitate communication between applications by structuring data in a format that can be easily exchanged and understood. XML is well-suited for representing complex data. However, it can be cumbersome and data-heavy, particularly in mobile applications. In contrast, JSON offers a more streamlined and readable format, utilizing key:value pairs that simplify data representation and reduce transmission size. Ultimately, the choice between XML and JSON depends on the specific needs of the application, including the complexity of the data and the environment in which it operates.

ComputerNetworkingNotes CCNA Study Guide XML and JSON Data Formats

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com