JSON

If you have not had any previous contact with JSON (JavaSCript Object Notation), it is inspired by Object Literals from JavaScript.
Although they look similar, it is often a mistake to think that it is the same.

Let's look at the example below.

This is a completly valid object in JavaScript.

Over the years, the data has been transmitted via the Internet in a variety of ways. The most popular of them in recent years has been XML.
It looks as this.

The most important criterion for sending data is speed.
When it was noticed that there were a lot of unnecessary characters during the transmission, they looked in the direction of JavaScript and Object Literals.
When we want to send firstName value using XML, we're also sending property's name. And we do it twice: <firstName> and </ firstName>.

To save the above example in the JSON format, we would do it this way.

It is worth remembering that each Object Literal Syntax is a valid JSON, but not every JSON is a valid Object Literal Syntax.
The above example is a valid Object Literal Syntax, but if we would like it to be valid as JSON we would have to wrap it in quotes.

JavaScript has a built-in method that allows you to parse to JSON. However, what we parse must have the correct syntax.
Therefore, in the example above, only the first console.log will be valid. The second one, without a wrapper in quotes, will end with error.

Next Post

I will talk about Functions. And why Functions are Objects