JSON Parse() Method in Javascript




JSON.parse()

Using javascript function JSON.parse() , text can be parsed into javascript object.
for JSON.parse() to function properly, it is required that the text must be in JSON format.

var text = '{"employeeName":"Deep","age":29,"employeeId":20089}';
var employee = JSON.parse(text);
console.log("employee name = "+employee.employeeName);
console.log("employee age = "+employee.age);
console.log("employee employeeId = "+employee.employeeId);

The output of the above program in the console is as below:

employee name = Deep
employee age = 29
employee employeeId = 20089

Where JSON.parse() is required??

Generally data received from server is of String type. To use, the data received from server as JSON in javascript, it is required to be parsed as JSON.