Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Data Serialization Concepts

Data serialization refers to the standard structuring of data in a machine-readable format that has specific data types and is formatted in a certain way so that machines can easily read and understand the data. There are many different available data serialization methods out there, some that are more applicable to some use cases than others, and some of them are much easier for humans to read as well as the computers to interpret them.

In this lesson we’re going to be talking about the structured data formats and their data types, so let’s jump right on in!

Our structured data formats make data machine readable, though human readability can make human interaction with the structured data more efficient.

We as the programmers are opening up a configuration file, an inventory file, or some other type of data which we typically feed into our code, however we also as the programmers sometimes need to write this file or check it for errors. We need to understand where there’s problems, which means the easier it is for us as humans to read this data, the more efficient that interaction would be.

In this course we’re taking a look at three different structured data formats, one of them we’ve already looked at pretty extensively being XML that extend stands for eXtensible Markup Language. The other two which we’re going to take a look at in this section of the course are, JSON, which is JavaScript Object Notation, and YAML which is YAML Ain’t Markup Language. This is called a recursive acronym since it has it’s own name in the definition of the acronym.

Typically the API that you’re using will dictate which structured data format that you will use in your code. Some APIs are coded to use some data formats others are not, so this will often dictate which data format that you need to work with and why it’s very important to be familiar with all three of these not only for the exam but also in your regular interactions as a Juniper DevOps engineer.

Let’s take a look at some of the commonalities between these structured data formats.

All structured data formats allow for various data types

Simple Data Types

Data types are, well, different types of data . First up, let’s talk about strings. These are sequences of alphanumeric characters interpreted as text. These are not numbers which arithmetic can be performed on, although a string may contain numbers, if is it a string type data then the numbers are interpreted as text instead of numerical data.

The eagle eyed of you may say well that’s actually a 31 character string example, others may say that this is actually a 24 character string. Well, minus the quotation marks the example is a 29 character string. The key here would be white space. The white space does count as a character. White space, meaning a space character generated by pressing the space bar on most keyboards, is a string character that would be stored in with your string.

As for numbers, there are different types of numbers. Integers are whole numbers 2 without a decimal point. Floats are numbers with a decimal point, described as a ‘floating point’. If you’re aware of others types of numbers because you’ve gone higher up in some maths, that’s excellent though we don’t really need to worry about that for the exam. It might come in handy in your programming.

arithmetic can be performed against numerical data types. As mentioned above, you could also have numbers stored as strings, in which case that is a character data type and not something that arithmetic can be performed against.

Now there are a couple other basic data types that you may not be so familiar with, two of these are booleans and the null data type. Booleans can only hold two different values and that would be a true or a false. This is often converted to a 1 or a 0 if casted to an integer. Generally you’ll use booleans in if statements, or something of that sort where something needs to be evaluated to true or false.

A null value is a special empty value type. This is where you have a variable that needs to be filled with something, but that something needs to be null, it needs to be empty. The use case you would typically see for the null value type is where something needs to exist but it needs to be empty or nothing. Null is not a false value, it is not a zero value, it is a nothing. it’s something that can be a little hard to wrap your head around.

Complex Data Types

In this lesson we’re going to take a closer look at our complex data types. There are two different complex data types we should know for the exam and we’ll be looking at. These are the list and the dictionary, in Python terms at least.

Different term for a list are a sequence or an array. This is in different terminology for different languages. You may have heard of an array in JSON, or a sequence in YAML, or a list in Python, however these are all describing the same complex data type.

Similarly for a dictionary in python, which is called a mapping in YAML, or an object in JSON. These terms too are all referencing the same complex data type.

Lists

Properties of a list/sequence/array

Let’s take a closer look at a list. so a list contains a countable number of ordered values. This means we have the ability to count up how long or how many items are in our list, and as well these items all have a particular order.

Example list as seen by square brackets and comma separated values

When we instantiate a list as we did here, ge-0/0/0 is the first item, ge-0/0/1 is the second item, ge-0/0/2 is the third item. When we call up the first item of our list here, we will always get “ge-0/0/0”. We can be sure of that because it is the first item in our list.

This might be a little hard to understand without a comparison. With a dictionary, or a mapping, there is no order to that data. It is stored in a different tree fashion as far as the computer is concerned, for very quick indexing and sorting. However, it is not actually stored in any particular order, so when you say “I want the first item out of this dictionary”, you don’t necessarily know what item it is you’re going to get, because it is stored in an arbitrary order, but lists are stored in the order that we create them.

Lists can be empty. We can create a list with no items stored within it, however the data type will still be a list.

The term “list” is used by many languages, and most notably it is what’s used by Python. In YAML this data construct is called a sequence, and in JSON it is called an array.

Dictionaries

properties of a dictionary/mapping/object

So let’s take a closer look at a dictionary now. A dictionary is a collection of key-value pairs. Generally it’s a more difficult data structure to understand. I have my key which identifies a value. The background algorithms allow for much more efficient data storage and retrieval and this is generally because items are not ordered in a particular way. They are structured in a different tree format so that they can be indexed by the keys very efficiently, but it causes the item order to not be preserved.

Example dictionary as seen by the braces, colons separating ‘keys’ and ‘values’, and comma separated pairs

A key is a string, whereas the value can be any simple or complex data type. In order to reference the value, we use the string key.

As we mentioned earlier, some languages do use a different term to describe a dictionary. In YAML it’s called a mapping, JSON it’s an object, and in Ruby it’s a hash. It can also be called an associative array for a more language agnostic term.



This post first appeared on CiscoLessons, please read the originial post: here

Share the post

Data Serialization Concepts

×

Subscribe to Ciscolessons

Get updates delivered right to your inbox!

Thank you for your subscription

×