Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda