My JSON string is structured like this:
[
{
"queryResult": {
"A": "12-04-2014",
"B": 1
}
},
{
"queryResult": {
"A": "13-04-2014",
"B": 2
}
},
{
"queryResult": {
"A": "14-04-2014",
"B": 3
}
}
]
I need to parse it and transform it into this format
[
{
"A": "12-04-2014",
"B": 1
},
{
"A": "13-04-2014",
"B": 2
},
{
"A": "14-04-2014",
"B": 3
}
]
I currently have a function that accomplishes this task using stringification and parsing, as shown below:
function justAnExample() {
var jsonData = exampleJSON(); //Retrieves the JSON
var finalJSON=JSON.stringify(jsonData[0]['queryResult']);
for (var i = 1; i < jsonData.length; i++) {
finalJSON = finalJSON+','+JSON.stringify(jsonData[i]['queryResult']);
}
return JSON.parse('[' + finalJSON + ']');
}
However, I am curious if there is a more efficient solution that involves working directly with the object notation itself.
P.S: I understand that the term "JSON object" may not be technically accurate, but I am mainly concerned with the JSON notation/format.
Edit
Here is a JS fiddle link for reference: