I have retrieved an object from JSON
data.
{
skills: {
extracted: [
{value: 'PHP'},
{value: 'JavaScript'},
{value: 'Python'}
]
},
experience : {
jobs : [
{
date_range : {
value : "September 2014 to January 2015"
},
company : {
value : "Direct Skill Systems LLC"
},
title : {
"value" : "Senior "
}
},
{
date_range : {
value : "October 2013 to January 2014"
},
company : {
value : "Seven Smarts LLC"
},
skills : [
{
value : "C#4 "
}
]
},
{... details of other job experiences ...}
]
},
education: {
institutions: [
{
name: {
value: "American University"
},
date_range: {
value: "July 2000 - November 2000"
}
},
{... details of other educational institutions ...}
]
}
}
How can I map
the data from JSON and organize the result as described below?
{
children: [
{
name: 'Skills',
children2: [
{name: 'PHP'},
{name: 'JavaScript'},
{name: 'Python'}
]
}
]
}
I found help in the answer provided by Jamiec.
var input = {
// Input JSON data here...
};
var data = {
children: [
{
name: 'Skills',
children2: input.skills.extracted.map(skill => ({name: skill.value}))
},
{
name: 'Experience',
children2: input.experience.jobs.map(job => ({name: job.date_range.value}))
},
{
name: 'Education',
children2: input.education.institutions.map(edu => ({name: edu.name.value, children2: [{name: edu.date_range.value}]}))
},
]
};
console.log(data);