menu EXPLORE
history NEW

What is JSON

JSON is the initials of JavaScript Object Notation and as its name indicates, it is a type of notation to save data. Although its name includes the Javascript programming language, the truth is that it is not exclusive to it and is used in many other programming languages, whether for scripting, backend, frontend, APP development, etc.

In this article we will learn the basics of JSON, what its advantages are, what applications it has in the world of technology and more specifically programming and we will end up analyzing some of its disadvantages and alternatives that exist.

Applications of the JSON format in programming

Developers and programmers use the JSON format mainly for 2 tasks: communication between different systems and storing information through databases.

Since computer systems were developed, the transmission of data between computers and different programming languages ​​has been a challenge. This required a standardized data type for any computer system.

This is how XML notation was born, globally used before the JSON format emerged. So, what advantages does JSON have over XML?

The main advantage is the processing time. XML is tag markup (very similar to HTML) that requires the creation of a tag tree to parse and understand the information.

This processing time is not necessary in the case of JSON, so it is much more effective on devices that have much fewer computational resources.

Currently there are several cases of application of the JSON format in terms of communication between different programming languages. A very clear example is websites.

The web pages consist of two very different parts. The client part (also known as Frontend) which is everything that we can see in our browser when we enter a website.

The second part is the server (also known as Backend) who operates all the code logic and who communicates with the database.

When we enter a web page, our browser communicates with the server to request the page we want to see. This communication is done through the JSON format since two very different programming languages ​​(frontend and backend) can speak using a standard communication and data transfer format, in this case JSON.

The second application of this type of notation is the persistence of information in different types of databases.

There are non-relational databases (NoSQL) that use the JSON format to store data. An example is the popular MongoDB. This database uses so-called collections, which are still a JSON format, where information is saved through key-value pairs.

For a few years now, SQL databases have also allowed information to be saved in JSON notation. Some examples are MySQL or PostgreSQL.

This type of format allows non-relational databases to be faster than relational databases since they do not have such a defined schema and processing can be much faster.

Syntax rules in JSON format

In order to comply with standardization, it is important to comply with a series of syntax rules to ensure that the JSON notation is correct.

Each of the objects are represented with two keys, one for the start and the other for the end. An object can contain different information. Let's take an example.

Imagine that you want to save the information of a dog. Within the object we could put the weight of the animal, age, hair color, breed among other information. The JSON object would look like this:

{“id” : 1, “breed” : “Beagle”, “age” : 3, “hair” : “brown”, “weight” : 12, “male” : true}

The id represents a number that unequivocally identifies the dog. Furthermore, we see different types of variables. Some are numbers, others are text, and we even have the male key that receives the value True, a data type known as Boolean.

All these types of data are recognized by the vast majority of programming languages, which allows effective communication between different systems.

json format example

Disadvantages of JSON notation

So far we have seen the characteristics of JSON and how, thanks to its capabilities, it has largely replaced the XML tag language for communication between computer systems.

To finish we will see a couple of examples of disadvantages that this type of data format can entail.

It does not have a defined scheme

When we work, for example, with relational databases, the data is stored in tables with a predefined schema. That is, each column in the table has a type of value that it can accept (text, numbers, booleans...) and if a value is added that does not belong to the predefined type then an error will appear.

The same goes for the length of the information entered. Other restrictions can also be specified such as that the value cannot be null or that it must be unique.

When we work with JSON this scheme does not exist so we can put any type of information. Many times this is not a problem since we do not need to have a previously defined schema, but in some situations it can be a disadvantage.

Therefore, sometimes its great flexibility can be a disadvantage and sometimes an advantage. Everything will depend on the requirements of the project we are working with.

Does not allow the use of comments

Another problem with JSON is that it does not allow comments to be inserted. In programming it is essential to always comment on the objects we are using. In this way, other users will be able to perfectly understand the information we are sending or the code we are developing.