What is json.stringify ?
If the stringify method sees an object that contains a toJSON method, it calls that method, and stringifies the value returned. This allows an object to determine its own JSON representation.
Example 1.
JSON.stringify([1,2,3,4,"open","the","door"]);
Result : produces "[1,2,3,4,"open","the","door"]"
Example 2.
var mangtug = {
name: "Manchester GTUG",
meetup: "First Monday of every month",
tags: ["gtug", "google", "manchester", "madlab"]
},
manjquery = {
name: "Manchester jQuery Group",
meetup: "First Tuesday of every month",
tags: ["jquery", "javascript", "jresig", "madlab"]
},
hybrid = {
name: "Hybrid!",
meetup: mangtug.meetup,
tags: manjquery.tags
};
var madlabGroups = [mangtug, manjquery, hybrid];
Result :
[{"name":"Manchester GTUG","meetup":"First Monday of every month","tags":["gtug","google","manchester","madlab"]},{"name":"Manchester jQuery Group","meetup":"First Tuesday of every month","tags":["jquery","javascript","jresig","madlab"]},{"name":"Hybrid!","meetup":"First Monday of every month","tags":["jquery","javascript","jresig","madlab"]}]