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.

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.
This tutorial is part of the tutorial "Network Automation and Programmability.". Other parts of this tutorial are as follows:
Chapter 01 Explain how automation impacts network management
Chapter 02 Compare traditional networks with controller-based networking
Chapter 03 Describe controller-based and software-defined architectures (overlay, underlay, and fabric)
Chapter 04 Separation of control plane and data plane
Chapter 05 North-bound and south-bound APIs
Chapter 06 Compare traditional campus device management with Cisco DNA Center-enabled device management
Chapter 07 Describe characteristics of REST-based APIs (CRUD, HTTP verbs, and data encoding)
Chapter 08 Recognize the capabilities of configuration management mechanisms Puppet, Chef, and Ansible
Chapter 09 Interpret JSON encoded data
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.
Author Laxmi Goswami Updated on 2025-10-16