JSON(JavaScript Object Notation)

JSON(JavaScript Object Notation)

ยท

2 min read

In this article, I have mentioned the array of objects. The JSON format is just like that with some restrictions.
Let's know more about it.

The first question that may be coming to your mind is what exactly JSON is?

thinking.gif

I already mentioned a little bit about it. But let's dive deep into the topic.

Objects and arrays are stored in the form of bits in the computer memory holding the addresses of their contents. Now, if you want to save the data or sent it to someone over the network. How you can do it?

One way is that you can share the entire memory along with the address of the value you are interested in. But this is a very ineffective approach.

A good approach is to convert it into JSON format (pronounced as "JASON") that stands for JavaScript Object Notation. It is used for communication and data storage over the Web.

As I mentioned earlier, it is similar to an array of objects but with some restrictions. Let's look at those restrictions ๐Ÿ‘‡

  • All property names have to be surrounded by double-quotes.
  • Only simple expressions are allowed. You can't include function calls, bindings, etc.
  • Comments are not allowed.

JSON data represented like this ๐Ÿ‘‡

{
     "household": true,
     "events": ["study", "sleep", "eat"]
}

JavaScript gives two functions to convert data to and from JSON.

  • JSON.stringify converts the data in JSON-encoded string.
  • JSON.parse converts JSON data into the value it is encoded.
let string = JSON.stringify({household: true, events: ["weekend"]});
console.log(string);
-> {"household": true, "events": ["weekend"]}

console.log(JSON.parse(string));
-> {household: true, events: ["weekend"]}

So this was all about JSON.

Thanks for reading!๐Ÿ˜Š

ย