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

149
Vistas
How could I make this JSON data usable on an API?

JSON data currently looks like this string:

["ID","Name","Age"],["212","David","38"]

And I would like for it to look like this:

{"ID":"212","Name":"David","Age":"38"}

Thanks for your help in advance

I found this code and it solves most of the issue

var columns = ["ID", "Name", "Age"];
var rows = ["212", "David", "38"];
var result =  rows.reduce(function(result, field, index) {
  result[columns[index]] = field;
  return result;
}, {})

console.log(result);

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You could do that with following steps:

  1. extract keys and values from array
  2. zip them to key match value
  3. use Object.fromEntries to create object key-value
let obj = [["ID","Name","Age"],["212","David","38"]]
let [keys, values] = obj;
let zipped = keys.map((key, i)=>[key, values[i]]);
let output = Object.fromEntries(zipped);
console.log(output);
about 4 years ago · Juan Pablo Isaza Denunciar

0

lets say let jsonVal = [["ID","Name","Age"],["212","David","38"], ["212","David","38"]] 0th index will have the keys and remaining is data

let newJsonVal = []  ​
 for (let i =1; i< jsonVal.length-1; i++) {
    ​let newObject ={}
     ​jsonVal[i].map((d,j) => { 
       ​newObject[jsonVal[0][j] = d;
      ​})
    newJsonVal.push(newObject)
 }

newJsonVal will have array of object as you need

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