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) language. HTLM is a static language. It defines how to add the text or a web page to a file and then add additional text called markup to denote formatting details for the text that should be displayed on the browser. For example, the markup included codes for headings, paragraphs, font types, sizes, colors, hyperlinks, etc.

XML (eXtensible Markup Language) was developed to make web pages dynamic. To make web pages dynamic, the files needed to store variables whose values could be changed and replaced over time by the web server. XML 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"?>
    <family>Switches and Hubs</family>
    <series>Cisco Catalyst 2400 Series Switches</series>
    <type>Cisco Catalyst 2400 Switch</type>
    <upTime>17 days, 12:35:08.12</upTime>

JSON data format

XML adds an opening and closing 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 data amount, 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 value of the variable. 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.

ComputerNetworkingNotes CCNA Study Guide XML and JSON Data Formats