var yourobj={
"c":{
"a":[{"name":"cable - black","value":2},{"name":"case","value":2}]
},
"o":{
"v":[{"name":"over the ear headphones - white/purple","value":1}]
},
"l":{
"e":[{"name":"lens cleaner","value":1}]
},
"h":{
"d":[{"name":"hdmi cable","value":1},
{"name":"hdtv essentials (hdtv cable setup)","value":1},
{"name":"hd dvd \u0026 blue-ray disc lens cleaner","value":1}]
}}
- first of all it's a good idea to get organized
- top level reference must be a more convenient name other that a..v... etc
- in o.v,o.i.e no need for the array [] because it is one json entry
my solution
var obj = [];
for(n1 in yourjson)
for(n1_1 in yourjson[n])
for(n1_2 in yourjson[n][n1_1])
obj[n1_2[name]] = n1_2[value];
Approved code
for(n1 in yourobj){
for(n1_1 in yourobj[n1]){
for(n1_2 in yourobj[n1][n1_1]){
for(n1_3 in yourobj[n1][n1_1][n1_2]){
obj[yourobj[n1][n1_1][n1_2].name]=yourobj[n1][n1_1][n1_2].value;
}
}
}
}
console.log(obj);
result
*You should use distinguish accessorizes when using [] method or dot notation
