JavaScript JSON

JSON: JavaScript Object Notation

The JavaScript JSON is is a lightweight human readable collection of data which is used to get a format for storing and transporting data. It is commonly used for data transfer as an alternative of XML.

JSON data format
JSON keep data in name-value pairs, separated by commas. Curly braces are used to hold objects and square brackets are used to hold arrays.

Syntax 1: For .json files:

{"First_Name" : "value"; "Last_Name": "value ";}

Syntax 2: For JSON objects:

var varName = { "First_Name" : "value";"Last_Name": "value "; }

JavaScript JSON Methods:

parse() method:
Use: To transform a JSON string into a JavaScript object.

stringify() method:
Use: To transform a JSON object into a JSON string representation.


<!DOCTYPE html>
var jsonString = '{"name":"Pooja","email": "[email protected]", "id": "345"}';
var jsonData = JSON.parse(jsonString);
var jsonString = {name:"Rupali", email: "[email protected]", id: 123};
var jsonData = JSON.stringify(jsonString);


[email protected]com
{"name":"Rupali","email":"[email protected]","id":123}
Please Share