I have a JSON string which looks like this:
[
{
"queryResult": {
"A": "12-04-2014",
"B": 1
}
},
{
"queryResult": {
"A": "13-04-2014",
"B": 2
}
},
{
"queryResult": {
"A": "14-04-2014",
"B": 3
}
}
]
And I need to parse it and change it to this
[
{
"A": "12-04-2014",
"B": 1
},
{
"A": "13-04-2014",
"B": 2
},
{
"A": "14-04-2014",
"B": 3
}
]
I already have a function for making that change, which is:
function justAnExample() {
var jsonData = exampleJSON(); //Obtains 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 + ']');
}
But, this method uses stringifying and then parsing JSON to recreate the JSON object, which works, but is there a better solution, in which I can work with the object notation itself.
P.S: I know the term "JSON object" is a semi-pseudo thing, and that only the JSON notation/format matters, but, just need to confirm if this is the proper way to do it.
Edit
Please find a JS fiddle for the problem