Access to JSON using node.js

Viewed 32

I'm trying to create convert project using nodejs, i have problem that i can not access to the data in JSON file, every time i have to chenge the reading part to get access, is there any other way to do that?

async function json2xlsxFromTo(jsonPath, xlsxPath) {
    try {
      let data = JSON.parse(
        fs.readFileSync(jsonPath, {
          encoding: "utf8",
          flag: "r",
        })
      ).catalog.book; // <===== i have to chenge (catalog.book) when i chenge the JSON file.
0 Answers
Related