Interpret JSON Encoded Data

json-key-value-pairs

JSON is the abbreviation of JavaScript Object Notation. It is a lightweight data interchange format that is user fiendly and easy readable by human or computers. So, you can easily guess the parameters used in a JSON file. Beside this, to learn the parameters used in JSON will improve your knowledge in this area. So, here, we will focus on JSON parameters and we will learnInterpret JSON Encoded Data.

 

JSON Key:Value Pairs

 

JSON Key:Value Pairs are defined with one column. These two values are divided with a colon. Here, the first part is the Key and the second part is Value. Key is the name of the Value and the Value part is the value of the key as its name implies.

As you can see below, there are four Key:Value pair. In the first Key:Value pair, Key is Heros and the Value of it is a Array (List).

 

{

“Heros”: [

{

“name”: “Aragorn”,

“race”: “Human”,

“role”: “King”

}

]

}

json-key-value-pairs

 

The other three Key:Value pairs are the members of the first Key:Value pair Value. Here, Keys are name, race and role. And Values are Aragorn, Human, King.

 

All these Key: Value pairs are in the curly brankets. And if we use multiple Key:Value pairs, we use a comma at the end of each one.

 

In JSON, Keys are always string. Beside, Values can be in different types. These types are:

 

  • Text
  • Numeric
  • Object
  • Array

 

A text value includes a string while a numeric value includes a number. We can use text in double quotes and numeric with single quotes.

 

JSON Objects

 Objects are the series of Key-Value pairs. In other words a collection of Key-Value pair. The similar structure in Python with Objects are Dictionaries. Curly brackets {} are used at the beginning and at the end of Objects. If there are multiple key:value pairs, they are separated by a comma.

 

We can also use such an example in our network automation:

 

{

“Routers”: {

“hostname”: “Backbone-1”,

“mng_ip_address” : “192.168.0.1”,

“mng_subnet_mask” : “255.255.255.0

}

}

 

Here, we use an Object in other words, in Python language, a Dictionary.

 

Here, let’s also give a Python Dictionary Example. There is a Python Dictionary example below:

 

“routers”:{“hostname”:”Backbone-1“, “mng_ip_address”:”192.168.0.1“, “mng_subnet_mask”:”255.255.255.0“}

 

JSON Arrays

Arrays are the ordered list of values. In Python, the similar data strcuture is Lists. Square brackets [] are jssued with arrays. Below, you can find an Array (List) example.

 

{

“Routers”: [

Backbone-1“,

Backbone-2“,

Edge-1“,

Edge-2

]

}

 

In network operation one of the most used programming language is Python. So, JSON objects and arrays are converted to Python language and generally called with the names in Python. In Python objects are called dictionaries and arrays are called lists.

 

json-objects-and-arrays

 

 

Back to: CCNA 200-301 > Automation and Programmability

Leave a Reply

Your email address will not be published. Required fields are marked *

CCNA 200-301

Collapse
Expand