I get a JSON from an external source which has an unknown number of keys. So for example the structure looks like:
data = [{
id: 1,
testObject_1_color: "red",
testObject_1_shape: "triangle",
testObject_2_color: "blue",
testObject_2_shape: "line",
},{
id: 2,
testObject_1_color: "green"
testObject_1_shape: "triangle",
},{
id: 3,
testObject_1_color: "brown",
testObject_1_shape: "square",
testObject_2_color: "black",
testObject_2_shape: "circle",
testObject_3_color: "orange"
testObject_3_shape: "square",
}]
To work with this data I'd need to convert it to something more useful like:
data = [
{object:1, color:"red", shape:"triangle"},
{object:2, color:"blue", shape:"line"},
{object:3, color:"green", shape:"triangle"}
]
The Number of testObject_x_color / shape
is undefined and can theoretically be anything between 0 and 100. Has anybody an idea how to walk through that collection without asking a 100 times if data.hasOwnProperty('testObject_x_color')...
?