I have this json structure.
x=[{
"value": 1.37,
"date_transacted": "2015-01-01"
}]
From this json structure, I want to produce the following json structure;
y1=[{
c: [{
v: "2015-01-01"
},
{
v: "1.37"
}]
}]
I have written the code to do this. It looks like this;
var y1 = [{ c:[ {"v":x[0].value}, {"v":x[0].date_transacted} ] }];
My problem comes when x
has several json key/value pairs. Something that look like this;
x=[{
"value": 1.37,
"date_transacted": "2015-01-01"
},
{
"value": 1.62,
"date_transacted": "2015-02-01"
},
{
"value": 1.83,
"date_transacted": "2015-03-01"
}]
What is an effective way to iterate my code through the array of objects to produce the desired json structure which should look like this?
y=[{
c: [{
v: "2015-01-01"
},
{
v: "1.37"
}]
},
{
c: [{
v: "2015-01-02"
},
{
v: "1.62"
}]
},
{
c: [{
v: "2015-01-03"
},
{
v: "1.83"
}]
}]