I have a task at hand where I need to combine two JSON arrays into a single JSON object that I have retrieved from an ajax call. Here is the code snippet that shows how I am fetching and storing the data:
var a = [];
var b = [];
var docsDatafromSOLR = response.response.docs;
var lengthOfSOLR_response = docsDatafromSOLR.length;
for (var i=0; i< lengthOfSOLR_response; i++) {
a.push({
latitude: docsDatafromSOLR[i].latitude,
longitude: docsDatafromSOLR[i].longitude
});
}
After this operation, array 'a' would look something like below:
"a": [
{
"latitude": 23,
"longitude":43
},
{
"latitude":42,
"longitude":67
}
]
'Array b' will follow a similar structure as well.
My question now is, how can I transform the individual JSON arrays 'a' and 'b' into a format like the one shown below? I have been searching for the syntax with no luck so far.
{
"1": {
"a": {
"latitude": "41",
"longitude": "-73"
},
"b": {
"latitude": "32",
"longitude": "-29"
}
},
"2": {
"a": {
"latitude": "47",
"longitude": "-69"
},
"b": {
"latitude": "42",
"longitude": "-35"
}
}
}