Saturday, May 16, 2020

Automation: How Important Data Format Is?

Programming Fundamentals: Data Formats: In my earlier post "Do I need to be programmer before learning Automation, SDN and NFV technologies?". The answer was no, all we need to understand how the data can be used to get various outputs which can be used for decision making process. One of the most important concept in programming language is how do we present the data to machines. In this post, I am trying to cover what is the importance of data formats in the programming language. How to choose which data format over the another?

Data format is nothing but the way how the data is being presented. Look at the below output which is easily readable by any human being as it is designed for human beings only but if machine has to read this data and take any action against it, unfortunately machine can't do anything. So we have to provide the data to machine in some data format which can be easily understood by machines and even for humans too :). See my earlier post of Junos Automation: Display Static Routes With PyEZ Table and View

Read the below which can be easily understood by any network engineer but might not be useful for any machine.

RP/0/0/CPU0:XR-1#show bgp vpnv4 unicast vrf VPN_ACME labels
Network            Next Hop        Rcvd Label      Local Label
Route Distinguisher: (default for vrf VPN_ACME)
*>         nolabel         24000
*>i100.100.100.2/32         21              nolabel

How machine can read the data and take action against it. To get this done, data has to be sent to machine in some format. So now the point is clear why data format is important in programming world. There are many data formats can be used in the programming world, but JSON, XML and YAML are the most popular one. We can represrnt any type of data by leveraging the any of the data format language. It's all about the developer or application comfort which data format they would like to use. Below is the data format for interface configuration in XML and JSON format:
XML Format
JSON Format { "ietf-interfaces:interface": { "name": "GigabitEthernet2", "description": "Configured by NETCONF", "type": "iana-if-type:ethernetCsmacd", "enabled": true, "ietf-ip:ipv4": { "address": [ { "ip": "", "netmask": "" }, { "ip": "", "netmask": "" } ] }, "ietf-ip:ipv6": {} } }

Doesn't matter which data format lanaguage is used but we have below mentioned common data elements in any type of data format: 1. Syntax
2. Representation
3. Key/Value
4. Lists or Arrays

Let's dig more how to use common data elements:
1. Syntax: XML syntax can be easliy recoganized as it starts with XMLNS and every data is represented in . However in JSON data format is represnetd in { Curly Braces for Arrays} and [ Square Brackets For List].

2 & 3. Representation and Key Value: In XML every data element is represented with KEY and VALUE notation. In the below example ip is KEY and "" is it's VALUE. netmask is KEY and "" is value.

4. List or Arrays: There is difference in Key and Value representation in JSON. ietf-interfaces:interface is main object KEY and name, description, type are all type of Key and Value. "," is used to seperate Key:Value. We can see [] square brackets which are showing the list of IP addresses.
  "ietf-interfaces:interface": {
    "name": "GigabitEthernet2",
    "description": "Configured by NETCONF",
    "type": "iana-if-type:ethernetCsmacd",
    "enabled": true,
    "ietf-ip:ipv4": {
      "address": [
          "ip": "",
          "netmask": ""
          "ip": "",
          "netmask": ""
    "ietf-ip:ipv6": {}

People who read this post also read :

No comments: