Sometimes, we want to parse JSON using Node.js.
In this article, we’ll look at how to parse JSON using Node.js.
How to parse JSON using Node.js?
To parse JSON using Node.js, we can use require.
For instance, we write
const config = require('./config.json');
to call require with the JSON file’s path and assign the returned JSON object to config.
require loads the JSON synchronously like any other module and the file is only read once when we call require and then cached thereafter.
Conclusion
To parse JSON using Node.js, we can use require.