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

224
Views
JSON data formetter in a particular way

I am using javascript.I have a json data set. I am trying to convert in a particular way. Can someone write the function so that I can convert it.

Given Json data:

{
   "members":[
      {
         "value":"view",
         "code":"reservations"
      },
      {
         "value":"view",
         "code":"dashboard"
      }
   ]
}

Trying to convert in:

{
  "members": [
    {
      "view_reservation": true,
      "edit_reservation": true,
      "create_reservation": true,
      "delete_reservation": true
    },
    {
      "view_dashboard": true,
      "edit_dashboard": true,
      "create_dashboard": true,
      "delete_dashboard": true
    }
  ]
}

Can someone write a function in javascript to convert it...

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

const data = JSON.parse(jsonData);
data.members = data.members.map(member => ({
  `${member.view}_${member.code}`: true,
  `edit_${member.code}`: true,
  `create_${member.code}`: true,
  `delete_${member.code}`: true
}));
about 4 years ago · Juan Pablo Isaza Report

0

you multiply output, we can just assume, that you always get 4 rows (CRUD-like)

Anyway, the approach of converting your object/array to the desired output can be done using something like this (where x is your current object):

var y = { "members": [] };
x.members.forEach(element => { y.members.push({ [element.code + '_' + element.value]: true}) } );

you can just edit the new object in the y.members.push to your desire

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!