I have a JSON file that comes in a particular structure (see Sample A), but I need it too be structured like Sample B.
Is it possible to reorganise the data in JS? If so, how do you go about this?
Sample A:
var myData = [
{
"date": "01/01/2017",
"here-value": "20",
"here-color": "pink",
"there-value": "24",
"there-color": "red",
},
{
"date": "02/01/2017",
"here-value": "80",
"here-color": "blue",
"there-value": "54",
"there-color": "red",
},
]
Sample B:
var myData = [
{
"date": "01/01/2017",
"here-value": "20",
"here-color": "pink"
},
{
"date": "01/01/2017",
"there-value": "24",
"there-color": "red"
},
{
"date": "02/01/2017",
"here-value": "80",
"here-color": "blue"
},
{
"date": "02/01/2017",
"there-value": "54",
"there-color": "red"
}
]
The reason I'm seeking to restructure the data, is to create objects that will feed into a visualisation using D3. The result will be similar to: http://jsfiddle.net/vw88/nzwLg96a/