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

155
Views
Crear un objeto simple a partir de una matriz anidada de objetos de matrices

Hola amigos, tengo mis datos json como este

 http://json-parser.com/24145c52

Quiero que cambie en esta forma (matriz de objetos

 const model = [ { instituteName:instituteName, courseName:courseName, studentFirstname:studentFirstname, studentSurname:studentSurname, appreciation:appreciation, finalGrade:finalGrade, behaviour:behaviour, completenessOfStapler:completenessOfStapler }, { instituteName:instituteName, courseName:courseName, studentFirstname:studentFirstname, studentSurname:studentSurname, appreciation:appreciation, finalGrade:finalGrade, behaviour:behaviour, completenessOfStapler:completenessOfStapler } ]

Por favor, ayúdame en esto

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

0

Primero tendrás que iterar sobre los datos.

Luego interactúa con los cursos del instituto.

Luego iterar sobre los estudiantes asignados a esos cursos

Se verá algo así

 const model = []; for (let i = 0; i < jsonParserData.institutes.length; i++) for (let j = 0; j < jsonParserData.institutes[i].courses.length; j++) for (let k = 0; k < jsonParserData.institutes[i].courses[j].students.length; k++) { model.push({ instituteName: jsonParserData.institutes[i].name, courseName: jsonParserData.institutes[i].courses[j].name, studentFirstname: jsonParserData.institutes[i].courses[j].students[k].firstName, studentSurname: jsonParserData.institutes[i].courses[j].students[k].surname, }); jsonParserData.institutes[i].courses[j].students[k].attributes.map((item) => { switch (item.option) { case "apreciation": model[model.length - 1].apreciation = item.value; break; case "finalGrade": model[model.length - 1].finalGrade = item.value; break; case "behaviour": model[model.length - 1].behaviour = item.value; break; case "completenessOfStapler": model[model.length - 1].completenessOfStapler = item.value; break; } }); }

O usando una sintaxis más nueva

 for (let institute of jsonParserData.institutes) for (let course of institute.courses) for (let student of course.students) { model.push({ instituteName: institute.name, courseName: course.name, studentFirstname: student.firstName, studentSurname: student.surname, }); student.attributes.map((item) => { switch (item.option) { case "apreciation": model[model.length - 1].apreciation = item.value; break; case "finalGrade": model[model.length - 1].finalGrade = item.value; break; case "behaviour": model[model.length - 1].behaviour = item.value; break; case "completenessOfStapler": model[model.length - 1].completenessOfStapler = item.value; break; } }); }
about 4 years ago · Juan Pablo Isaza Report

0

Puede hacer esto ejecutando un simple sobre los datos como este

 // This is an empty array to store data const model = []; // This is the data array const dataArr = []; // looping over the main array dataArr.map((data) => { let Obj = { instituteName: "", courseName: "", studentFirstname: "", studentSurname: "", appreciation: "", finalGrade: "", behaviour: "", completenessOfStapler: "", }; // looping over the courses array inside main array data.map((course) => { // looping over the students array inside main course course.map((student) => { let Obj = { instituteName: data.name, courseName: course.name, studentFirstname: student.firstName, studentSurname: student.surName, appreciation: "", finalGrade: "", behaviour: "", completenessOfStapler: "", }; model.push(Obj); }); }); });
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!