Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
How do I browse directories for json files (JavaScript)?

I want to browse directories for json files and merge all json files into one json file per directory. My javascript skill is at beginner level.

The javascript code needs to run by calling it in the Terminal, not in the browser.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can make use of glob npm package to retrieve all json file paths in the directories.

glob : https://www.npmjs.com/package/glob

you can simply go with :

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 return paths for all the json files 

    for (const jsonFilePath of jsonFilePaths) {
        let content = await fs.readJsonSync(jsonFilePath);
        Object.assign(data,content);
    }

     await fs.writeJson(<filePath>, data, {spaces: 2});
    //here specify your file path
}

ps. I am a new contributor, might have misread the question.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!