Beginner’s Guide

What is JSON? And why do you need it?

Rizwan Hasan
TechLearners
Published in
4 min readAug 21, 2019

--

JSON Logo

Before going on to the topic JSON, I would like to discuss a simple example because it will be a lot easier to explain JSON after the example.

Suppose we are developing a desktop software or a web application. So, for the desktop software we need to save the changes of settings that users have made so that when he/she opens the software again at another time, he/she doesn’t need to change the settings again as he/she changed it earlier. Also, it’s a very annoying thing for a user to config the same changes in every start. Now, what about web applications? Web apps have one or more databases to store changes. Let’s think about a drawback here. Web apps need to store many temporary configuration or data to serve the user with a good experience for that session. And it’s an obvious thing that, developers can’t let an app to make the database busy for some temporary session data. Now, the question comes about how we store these changes or temporary data on storage? Confused? Again thinking about using databases like Oracle, Mariadb? Of course, we can do that but it’s not an efficient solution here. Ok, Keep down your thinking a bit and I’m keeping all the hard things aside, just store the data as a Text file. Wow, our storing problem is solved. But a new problem is knocking at the door, how to retrieve the data and get the same data structures in the same manner that we had applied in the application? On a simple text file, there are lackings of data formation for the data structures that we use in any program. Here comes the life-saving concept of data serialization, also we are very close to jumping on JSON.

What is Data Serialization?

Data Serialization is the process of converting structured data to a format that allows sharing or storage of the data in a form that allows recovery of its original structure when needed. Reason of serializing data is finding some sort of universal format that can be easily shared across different applications.

What is JSON?

JSON is a data interchanging format that uses human-readable text to transmit data objects consisting of data structure and it’s the most widespread format for data serialization. Simply JSON is text, written with JavaScript object notation. “JavaScript Object Notation” is the full form of JSON. Many developers don’t like JavaScript because of their perspectives. But don’t worry, it’s alright if your knowledge is empty about JavaScript.

An example of JSON Schema (credit: Wikipedia)

Why JSON?

JSON is mainly intended for data interchanging among the applications. Parsing data from one application to another through JSON is so much easy because of its language-independent data format. Almost every programming language has JSON support through official and 3rd party. Now, referencing my example, JSON can be used as a configuration or temporary data storing file also for any application. There is an important fact that JSON lacks Abstract Data Type (ADT) feature because of its data serialization format which breaks the opacity of ADT by potentially exposing private implementation details.

A very popular database named “MongoDB” uses JSON-like documents with schema.

Basics of JSON

JSON uses “.json” for filename extension. You can write JSON file using normal text editors like Windows’s built-in Notepad. JSON supports String, Number, Object (JSON object)/Hashmap, Array/List, Boolean and Null data types.

Let’s see some examples:

String

Number

JSON names require double quotes (“”).

JSON uses colon (“:”) for separating names and value.

Objects / Hashmap

Here key “student” have a object value and that object have some names.

JSON uses curly braces (“{}”) for object separation and commas (“,”) for names separation.

Array / List

Here key “student” have an array value and that array have some name element.

JSON uses square brackets (“[]”) for array declaring and commas (“,”) for element separation.

Boolean

Null

Data types in Nested manner

Explanation:

Here we are storing some student's information. First, there is an object which’s key is named “students” and value is an array blocked with square brackets. In the array, there is two student’s information. Every element of the array is also an object and they contain some information name, age, department, sex, paid and cgpa. Name, department, and sex are strings. Id, age and, cgpa are number. Lastly paid is boolean.

Conclusion

So far I discussed JSON but still, there are a lot of things to know about like how to use it with different programming languages and how to do data interchanging between two or more languages. Here I only focused on giving the basics because after this pretty basic you are ready to go with JSON more advanced and also with the upgraded version of JSON called YAML. To learn more about JSON, I suggest this free online tutorial from Tutorialspoint here. In the future, I will try to cover how to use JSON with popular programming languages like Python, Java, Kotlin, and C++.

If you liked my writing you can inspire me by giving a Clap. You can follow me on Medium and I’m also available on Twitter here. Don’t forget to share your opinion on the comment section below.

--

--

Rizwan Hasan
TechLearners

Experienced Software Engineer specializing in backend development, debugging, and cloud computing with Python, FastAPI, Azure, AI integration, and CI/CD skills.