JavaScript JSON

Global Objects - JSON


JSON an acronym for JavaScript Object Notation.

It is a lightweight data interchange format used for storing and sharing data between client and server over the network.

For example, to store and share customer information over web, this is how the corresponding JSON data will look like :

Global Objects JSON example

In this code, variable dataJSON is exactly like the literal notation syntax used for object creation in JavaScript. Whereas there is a very small difference.

For JavaScript objects we do not put the key in quotes and if values are of string data type they can be put in single or double-quotes.

But for JSON object, it is mandatory to put the key inside the double quotes and all the values of type string inside the double-quotes.

javascript object vs JSON Object

JSON is a text-only format. It travels over the network as a string.

In this context, there are two important methods given by JSON object. Let us learn and implement them.

JSON object method description and example

Demo :

JS code :

function User(name, email, mobile, password) { = name; = email; = mobile;
  this.password = password;
var user = JSON.parse(
  "User Details: " +
    " name is " + +
    " mobile is " + +
    " email is " +
var dataJSON = {
	  customers: [
		{ firstName: "Bob", lastName: "Morry" },
		{ firstName: "Albert", lastName: "Smith" },
		{ firstName: "Kate", lastName: "Ward" }
	  "JSON string: " + JSON.stringify(dataJSON));    
	var stringJSON = ‘{"firstName":"Bob", "lastName":"Morry"}’;
	  "JSON string: " +
		JSON.stringify(JSON.parse(stringJSON) );
#javascript_object_to_json #JSON_object_in_javascript #javascript_json #javascript_json_stringify #javascript_array_to_json #javascript_create_json_object

(New page will open, for Comment)

Not yet commented...