Converting an object to JSON and back again
JSON (JavaScript Object Notation) is very closely related to JavaScript objects because it's a subset of JavaScript. This task will demonstrate how to use the building blocks of JSON conversion: JSON.parse
and JSON.stringify.
Getting ready
We'll need to create two new files called profiles.js
and json_and_back.js
.
How to do it...
Let's create the object that we'll later be converting to JSON.
module.exports = { ryan: { name: "Ryan Dahl", irc: "ryah", twitter: "ryah", github: "ry", location: "San Francisco, USA", description: "Creator of node.js" }, isaac: { name: "Isaac Schlueter", irc: "isaacs", twitter: "izs", github: "isaacs", location: "San Francisco, USA", description: "Author of npm, core contributor" }, bert: { name: "Bert Belder", irc: "piscisaureus", twitter: "piscisaureus", github: "piscisaureus", location: "Netherlands", description: "Windows support, overall contributor" }, tj: { name: "TJ Holowaychuk", irc: "tjholowaychuk", twitter...