JavaScript Lessons

How JSON in JavaScript works

This lesson will be about JSON. Shortcut JSON means JavaScript Object Notation, Is possible to say, that JSON is a JavaScript object written as text string.

Here is simple sample od JSON, we see that the object is written in curly braces, and the properties are always written in quotation marks. We can easily access the properties of this object. In this case we can write for example user firstname into document and see, that it works correctly.

Now we comment this first JSON object and uncomment array. JSON supports array, so is easy to write into JSON more objects, individual objects must be separated by a comma. We can again easily access to object in array index 1 for example.

So we can write into document array one firstname and array one lastname into document a and see, that it works correctly. We comment on the array and see how easy it is to write an object to JSON.

We see that we have the User class, which has the first name, last name, and age properties defined in the constructor. Then we create an instance of the User class named user one and add arguments to the parameters. In the next step, we will use the Stringify method of the JSON class and write JSON stringify user one.

Now we can write user one in the document and we see that user one is now in JSON format. The complete source code as well as the complete text tutorial for this video is located in the link written in the video description. Thank you for watching this video and if you like, subscribe to this channel and put like.

Download source files