concept JSON text file in category data

appears as: JSON text file, JSON text files
Data Wrangling with JavaScript

This is an excerpt from Manning's book Data Wrangling with JavaScript.

Listing 3.5 A function to import a JSON text file (toolkit/importJsonFile.js)
const file = require('./file.js');    #1  

//
// Toolkit function to import a JSON file.
//
function importJsonFile (filePath) {    #2  
 return file.read(filePath)    #3  
 .then(textFileData => {    #4  
 return JSON.parse(textFileData);    #5  
 });    #4  
};    #6  

module.exports = importJsonFile;    #6  

#1   Requires our file toolkit module
#2   Defines our toolkit function to import a JSON file
#3   Uses our file.read toolkit function to read a JSON text file into memory
#4   Invokes the callback to handle the text data loaded from the file
#5   Uses JSON.parse to parse the JSON text data to the CDR
#6   Exports the toolkit function so that we can use it with other Node.js modules

Figure 3.9 Importing a JSON text file to the CDR

c03_09.eps
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest