JSON is a format for storing and transporting data.
JavaScript Objects can be converted into JSON, and JSON can be converted back into JavaScript Objects.
var myObj = { "name":"John", "age":31, "city":"New York" }; var myJSON = JSON.stringify(myObj); console.log( myJSON );
In JSON, values must be one of the following data types:
JSON values cannot be one of the following data types:
//Convert a string written in JSON format, into a JavaScript object. var myJSON = '{ "name":"John", "age":31, "city":"New York" }'; var myObj = JSON.parse(myJSON); console.log( myObj.name );// w ww .ja v a2 s . c o m