How to Parse JSON using Node.js? Last Updated : 19 Apr, 2024 Comments Improve Suggest changes Like Article Like Report JSON stands for JavaScript Object Notation. The text-based data exchange format data exchange format allows you to transfer data between different languages and platforms. JavaScript is commonly used to interact with JSON files. JSON parsing is a common task when working with data from APIs, configuration files, or databases. In this article, we will learn about How to parse JSON using Node.js. The below mentioned are the approaches to parse JSON data in Node.js: Table of Content Using JSON.parse() methodReading JSON from a FileUsing require() methodUsing JSON.parse() methodThis is the simplest way to parse JSON by using the built-in JSON.parse() method. This method takes a JSON string as input and returns a JavaScript object. Example: This example shows the use of JSON.parse() method to parse JSON. JavaScript const jsonString = '{"name": "John", "age": 30}'; const jsonObject = JSON.parse(jsonString); console.log(jsonObject.name); console.log(jsonObject.age); OutputJohn 30 Using fs moduleIf your JSON data is stored in a file. you can read the file using Node.js's built-in fs module and then parse the JSON string. Example: This example shows the use fs module to parse JSON. JavaScript const fs = require('fs'); fs.readFile('data.json', 'utf8', (err, data) => { if (err) { console.error(err); return; } const jsonObject = JSON.parse(data); console.log(jsonObject); }); JavaScript // data.json {"name": "John", "age": 30} Output: {"name": "John", "age": 30}Using require() methodYou can also directly require a JSON file. When you use require() with a .json file Node.js automatically parses the JSON data and returns it as a JavaScript object. Example: This example shows the use of require() method to parse JSON. JavaScript const jsonObject = require('./data.json'); console.log(jsonObject); JavaScript // data.json {"name": "John", "age": 30} Output {"name": "John", "age": 30} Comment More infoAdvertise with us Next Article How to Parse JSON using Node.js? J jaimin78 Follow Improve Article Tags : JavaScript Web Technologies JSON Similar Reads How to Send JSON Response using Node.js ? NodeJS is the runtime environment, which can execute the javascript code on any platform. It is widely used to create and run web application servers because of its salient features.During production, several times we need to send the resources or some type of information as a response, and javascri 5 min read How to read and write JSON file using Node ? Node JS is a free and versatile runtime environment that allows the execution of JavaScript code outside of web browsers. It finds extensive usage in creating APIs and microservices, catering to the needs of both small startups and large enterprises.JSON(JavaScript Object Notation) is a simple and t 3 min read How to Add Data in JSON File using Node.js ? JSON stands for Javascript Object Notation. It is one of the easiest ways to exchange information between applications and is generally used by websites/APIs to communicate. For getting started with Node.js, refer this article.Prerequisites:NPM NodeApproachTo add data in JSON file using the node js 4 min read How to convert tabular string to JSON using Node.js ? Tabular: Information that is displayed in a table with rows and columns is known as "tabular format". A data table is an organized and practical approach to displaying a significant amount of information that contains repeated data items. The majority of office productivity software packages, includ 5 min read Node.js querystring.parse() Method The querystring.parse() method is used to parse a URL query string into an object that contains the key and pair values of the query URL. The object returned does not inherit prototypes from the JavaScript object, therefore usual Object methods will not work. During parsing, the UTF-8 encoding forma 3 min read Like