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

184
Views
How to get specific key and value from a long json object while iterating it in node.js

I am trying to parse a csv file in node.js , i am able to parse the csv file and can print the content , the contents are coming as a from of a json object.Now my target is to iterate the json object and take out specific key and values from each block and use them in a Query which will do some DB operations.But the problem is while i am trying to iterate the json only first key and values of the first block is printed. Let me post the code what i have done

 fs.createReadStream(path)
  .pipe(csv.parse({headers:true ,ignoreEmpty : true}))
  .on("error",(error) => {
   throw error.message;
   })
   .on("data",function(data){
    if(data && data!=={}){
    Object.keys(data).forEach(function(k){
     if(k==='name' || k==='Office'){
    let selectQury = `select name,Office from myTable where  name = ${data['name']} and Office 
    =${data[Office]};
    db.query(selectQury,(err,res)=>{
     if(err){
      console.log('error',null);

This my json which i parse from the csv looks like

  {
    id:1,
    name:"AS",
    Office:"NJ"
    ........
    ACTIVE: 1.
  },
   {
    id:2,
    name:"AKJS",
    Office:"NK"
    ........
    ACTIVE: 2.
  }

so now what i want is in the select Query the parameters will be passed like

 let selectQury = `select name,Office from myTable where  name = "AS" and Office  = "NJ"; 
 in the first iteration
 let selectQury = `select name,Office from myTable where  name = "AKJS" and Office = "NK";  
 in the second iteration and so on as the csv grows.

I am not able to do it ,please help . Thanks in advance. I am new to node.js & tricky javascript operations.

about 4 years ago · Juan Pablo Isaza
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!