If you're looking to fetch paths for all JSON files within directories, one option is to utilize the glob npm package.
For more information on glob, check out: https://www.npmjs.com/package/glob
Here's a simple approach:
const glob = require("glob");
const fs = require('fs-extra');
async function processJsonData(){
let parentDirectoryPath = '<specify path here>';
let data = {};
let jsonFilePaths = glob.sync(`${parentDirectoryPath}/*/*.json`);
//this will provide paths for all JSON files
for (const jsonFilePath of jsonFilePaths) {
let content = await fs.readJsonSync(jsonFilePath);
Object.assign(data,content);
}
await fs.writeJson(<filePath>, data, {spaces: 2});
//specify your file path here
}
ps. As a new contributor, I might have misunderstood the question.