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

181
Views
JSON to CSV/Excel in Nodejs

I am trying to convert the JSON:

Results: console.log((${JSON.stringify(results)});


[
[{"field":"StudentID","value":"A"},{"field":"Total Marks","value":"27853"}],[{"field":"StudentID","value":"B"},{"field":"Total Marks","value":"14337"}],[{"field":"StudentID","value":"C"},{"field":"Total Marks","value":"1324"}],[{"field":"StudentID","value":"D"},{"field":"Total Marks","value":"362"}],[{"field":"StudentID","value":"E"},{"field":"Total Marks","value":"209"}]]

to something a .csv file or excel file and download

Student ID  Total Marks
A           27853
B           14337
C           1324
D           362
E           209

Could someone provide a snippet of the js code that will help to implement this?

What I tried:

const json2csvParser = new Parser();
            results.forEach(element => {
                const csv = json2csvParser.parse(element);
                console.log(csv);
            });
            const csv = json2csvParser.parse(results);
            console.log(csv);

This just prints in the console as :

"field","value"
"Student ID","A"
"Total Marks","27853"
"field","value"
"Student ID","B"
"Total Marks","14337"
"field","value"
"Student ID","C"
"Total Marks","1324"
"field","value"
"Student ID","D"
"Total Marks","362"
"field","value"
"Student ID","E"
"Total Marks","209"
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Download csv-parser npm pack.

npm i -s csv-parser

And for download;

const fs = require("fs");
fs.writeFileSync("demo.csv", csv);
console.log("Done!");

Basic tutorial for run at js page;

// (A) DATA ARRAY
var data = [
    ["Alpha", "Beta"],
    ["Charlie", "Delta"],
    ["Echo", "Foxtrot"]
  ];
  
  // (B) WRITE TO FILE
  const fs = require("fs");
  const stream = fs.createWriteStream("demoC.csv");
  for (let i of data) { stream.write(i.join(",") + "\r\n"); }
  stream.end();
  console.log("Done!");
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!