javascript / beginner
Snippet
Parsing JSON Data
In Node.js, JSON.parse() is essential for converting string data (like from a file or API) into a JavaScript object.
snippet.js
javascript
1
2
3
const json = '{"name": "NodeJS"}';const data = JSON.parse(json);console.log(data);
nodejs
Breakdown
1
const json = '...';
A string formatted as a JSON object.
2
JSON.parse(json)
Converts the string into a real object that JavaScript can work with.