I have a CSV file that is structured like this:
"","Sequence","Paths","sequence_length"
"1","Social -> Social -> Social -> Social -> Social -> Social -> Social -> Social",29,8
"2","Social -> Social -> Social -> Social -> Social -> Social -> Social",30,7
"3","Social -> Social -> Social -> Social -> Social -> Social",40,6
"4","Social -> Social -> Social -> Social -> Social",71,5
"5","Social -> Social -> Social -> Social",156,4
"6","Social -> Social -> Social",273,3
"7","Social -> Social -> SEO",40,3
"8","Social -> Social",729,2
"9","Social -> SEO -> Social",51,3
"10","Social -> SEO",180,2
"11","Social -> SEM",56,2
My goal is to transform this data into a JSON tree structure as shown below:
{
"name": "Social",
"children": [{
"name": "Social",
"children": [{
"name": "Social",
"children": [{
"name": "Social",
"children": [{
"name": "Social",
"children": [{
"name": "Social",
"children": [{
"name": "Social",
"children": [{
"name": "Social",
"Path": 29
}]
}]
}]
}]
}]
}]
}]
}
Each touchpoint represented by 'Social' in the CSV file signifies a child node of the previous one, with the number of paths being added to the final node.
To achieve this, I am splitting the 'Social' elements into an array like this:
data.forEach(function(d){
var x = d.Sequence.split(' -> ');
If anyone could assist me with parsing this information into JSON format, it would be greatly appreciated. Thank you!