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: 1.1.1.1:0 (default for vrf VPN_ACME)
*> 100.100.100.1/32 0.0.0.0 nolabel 24000
*>i100.100.100.2/32 2.2.2.2 21 nolabel
RP/0/0/CPU0:XR-1#
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: