JSON — The What, Whys’ and Hows’

Linu Bajy
3 min readMay 12, 2023

--

Hello Everyone,

Let me introduce to The JSON Format!

Why do we need JSON?

We all know the importance of Data right! The world runs on Data. Let me give you a simple example, how do u think AI models are trained? Yup, its Data or to be more specific, its called a Dataset. So now I hope you get a better perspective of how useful data can turn into, or more importantly how the data is stored.

Before JSON, we had XML , or the eXtensible Markup Language. This is a format in which data is stored , that can be read and interpreted.

XML was used for web service responses , but JSON was preferred for multiple reasons:

  • Lightweight- Significantly reduced the size
  • Easy to read and write
  • Used for various collection objects like Array, Dictionaries etc. XML used just strings

However, XML was better in terms of security perspective , than JSON . And Hence these are preferred for Production Servers.

Taking a snippet out of Wikipedia

JSON grew out of a need for a real-time server-to-browser session communication protocol without using browser plugins such as Flash or Java applets, the dominant methods used in the early 2000s.

The co-founders agreed to build a system that used standard browser capabilities and provided an abstraction layer for Web developers to create stateful Web applications that had a persistent duplex connection to a Web server by holding two Hypertext Transfer Protocol (HTTP) connections open and recycling them before standard browser time-outs if no further data were exchanged.

So basically, they needed a format that was quicker and wasn’t dependent on the browser plugins or any language for that matter.

XML code snippet
-----------------
<?xml version="1.0" encoding="UTF-8"?>
<obj>
<to>ABC</to>
<from>XYZ</from>
<heading>Intro to JSON</heading>
<body>Lets get going!!!</body>
</obj>

PS: Notice the tags!!
JSON code snippet
------------------
{ "obj" :
{
"to": "ABC",
"from": "XYZ",
"heading": "Intro to JSON",
"body": "Lets get going!!!"
}
}

What is JSON?

Now that we know why XML was replaced, lets dive into what it was actually replaced with.

JSON is JavaScript Object Notation. Its a way through which programs in an Application can communicate with each other. [1]

Like mentioned earlier, JSON can have multiple object types like Arrays etc.

An object in JSON is enclosed within “{ }” — parenthesis. The values within it can be in key value pairs. The value could be a collection of objects as well.

Say if I need an object called name, I can write a JSON file , with the content something like this- { “name”: “Linu” }. Each key value pairs are separated by colon “:”.

Note:

  • If I have multiple key value pairs, they need to be separated by a comma, except for the last pair.
  • Also remember to put a space after every “:”
  • Indentation doesn’t matter as long as you’ve closed all brackets!

A much more complex example for JSON

{
"name": "Linu",
"gender": "Female",
"role": "Devops Engineer",
"parents": [
{
"name": "ABC",
"gender": "Male"
},
{
"name": "XYZ",
"gender": "Female"
}
]

}

So , from this example, parent is key which has an array of 2 objects. Taking the real life example, I think its self explanatory. In this way multiple object can be added as much as needed.

Now Why is JSON important?

Going with the current trend, we see Docker and Kubernetes tools. These tools make use of some configuration files for creating and deploying containers and other objects. It alternatively uses YAML as well .

The responses that we get from kubectl ( Kubernetes API ) is in JSON format. Hence it is important to know how to query from JSON path.

Now , we know the What and Whys of JSON , and maybe just a bit of the Hows’ , (its just the tip of the Iceberg!). Lets explore more of this, in the upcoming posts!

--

--

Linu Bajy
Linu Bajy

Written by Linu Bajy

Enthusiastic Learner . DevOps Professional .

No responses yet