Common Data Formats in Programming
Common Elements in a Data Format
• Format syntax
• Objects Representation
• Key / Value notation
◇ Values can be objects, lists, strings, numbers, boolean
• Arrays or List notation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
JSON
• JSON stands for JavaScript Object Notation
• A human readable data structure that application use to store, transfer and read read
• A data-interchange text format
• Notated with { } for objects, [ ] for arrays
• Key / Value representation “key”: value
• Whitespace not significant
JSON Object
• Data surrounded by { }
• An object can contain other objects or data entries
• Key / Value set separated by comma
• No comma at the end !
{
"ietf-interfaces:interface": {
"name": "GigabitEthernet2",
"description": "Wide Area Network",
"enabled": true,
"ietf-ip:ipv4": {
"address": [
{
"ip": "172.16.0.2",
"netmask": "255.255.255.0"
}
]
}
}
}
JSON List
• List of data
• Can be composed of JSON objects
• Notated with brackets
• Comma separated
{
"addresses": [
{
"ip": "172.16.0.2",
"netmask": "255.255.255.0"
},
{
"ip": "172.16.0.3",
"netmask": "255.255.255.0"
},
{
"ip": "172.16.0.4",
"netmask": "255.255.255.0"
}
]
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XML
• XML stands for eXtensible Markup Language
• A human readable data structure that applictions use to store, transfer and read data
• Designed for Internet
• Schema or namspace defines data model
XML Object
• A related set of data surrounded by <tags></tags>
• An object can contain other object or data entries
• <key>value</key> contained within the object tags
• Whitespace not significant
<!-- XML Object -->
<?xml version="1.0" encoding="UTF-8" ?>
<interface xmlns="ietf-interfaces">
<name>GigabitEthernet2</name>
<description>Wide Area Network</description>
<enabled>true</enabled>
<ipv4>
<address>
<ip>172.16.0.2</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
</interface>
XML List
• List of data
◇ Can be composed of XML objects
• Repeated instance of <tags></tags> for each element
<!-- XML List -->
<?xml version="1.0" encoding="UTF-8" ?>
<addresses>
<ip>172.16.0.2</ip>
<netmask>255.255.255.0</netmask>
</addresses>
<addresses>
<ip>172.16.0.3</ip>
<netmask>255.255.255.0</netmask>
</addresses>
<addresses>
<ip>172.16.0.4</ip>
<netmask>255.255.255.0</netmask>
</addresses>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
YAML
• YAML Ain't Markup Language
• A human readable data structure that applications use to store, transfer and read data
• Minimalist format commonly used for configuration files
• Whitespace indentation defines structure
◇ No commas
• Key / Value representation
◇ key: value
YAML Object
• Related set of data at the common identation level under name
• An object can contain other objects or data entries
• key: value pairs left aligned
---
ietf-interfaces:interface:
name: GigabitEthernet2
description: Wide Area Network
enabled: true
ietf-ip:ipv4:
address:
- ip: 172.16.0.2
netmask: 255.255.255.0
YAML List
• List of data
• Can be composed of YAML objects
• Uses “-” character to indicate a list element
---
addresses:
- ip: 172.16.0.2
netmask: 255.255.255.0
- ip: 172.16.0.3
netmask: 255.255.255.0
- ip: 172.16.0.4
netmask: 255.255.255.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Review
• Importance of the Audience
• Common data formats in programming
◇ XML
◇ JSON
◇ YAML
• Data formats are mostly interchangable
Index