Question: How to convert this code so that a function will read an external JSON data file then convert data into a JavaScript object using JSON.parse

How to convert this code so that a function will read an external JSON data file then convert data into a JavaScript object using JSON.parse().
The value of the parameter that you will pass to the function is: "data/books.json".
The second parameter is the name of the function that must be run after the file has been read from the server. This is your callback function.
HERE IS Mlet tableBody = document.querySelector('tbody');
function booksObject(){
let books ={
9781118876138 : {
title : "DATA SCIENCE & BIG DATA ANALYSIS",
price : 60.24,
quantity : 1},
9781107186125 : {
title : "PRINCIPLES OF DATABASE MANAGEMENT",
price : 77.25,
quantity : 1},
9781587205880 : {
title : "CCNA ROUTING & SWITCHING PORTABLE COMMAND GUIDE",
price : 24.26,
quantity : 2},
9781119288312 : {
title : "CCNA ROUTING AND SWITCHING : EXAM",
price : 73.50,
quantity : 2},
9781305078628 : {
title : "HANDS-ON MICROSOFT WINDOWS SERVER 2016",
price : 108.75,
quantity : 1},
9781541895386 : {
title : "INTRODUCTION TO WEB DEVE",
price : 65.25,
quantity : 1},
9781943872381 : {
title : "MURACH'S PHP AND MYSQL",
price : 43.25,
quantity : 1},
9780134167008 : {
title : "REVEL FOR LIANG JAVA ACCESS CARD",
price : 86.75,
quantity : 1}
}
if (document.readyState === 'loading' ){
document.addEventListener('DOMContentLoaded', booksObject);
}else {
booksObject();
}
function createTableRows(books){
const fragment = document.createDocumentFragment();
for (const books of data){
const row = document.createElement('tr');
const isbnCell = document.createElement('td');
const titleCell = document.createElement('td');
const priceCell = document.createElement('td');
const quantityCell = document.createElement('td');
const totalCell = document.createElement('td');
isbnCell.textContent = book.isbn;
titleCell.textContent = book.title;
priceCell.textContent = book.price;
quantityCell.textContent = book.quantity;
const totalPrice = book.price * book.quantity;
totalCell.textContent = totalPrice;
row.appendChild(isbnCell);
row.appendChild(titleCell);
row.appendChild(priceCell);
row.appendChild(quantityCell);
row.appendChild(totalCell);
fragment.appendChild(row);
}
tableBody.appendChild(fragment);
}
createTableRows(books);
};Y CODE:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!