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

153
Views
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 answers
Answer question

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 Report

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 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!