I am looking to merge two arrays containing JSON objects while retaining duplicate keys by adding a prefix to the keys. In this specific scenario, the data from 'json2' is replacing the data from 'json1' due to having identical keys, but I want to keep both sets of data. Thank you.
var json1 = [
{
"Column1": "json1",
"Column2": "json1",
},
{
"Column1": "json1",
"Column2": "json1",
}
];
var json2 = [
{
"Column1": "json2",
"Column2": "json2",
},
{
"Column1": "json2",
"Column2": "json2",
}
];
console.log(angular.extend(json1, json2));
The current output is:
[
{
"Column1": "json2",
"Column2": "json2",
},
{
"Column1": "json2",
"Column2": "json2",
}
];
However, the desired output is:
[
{
"json1Column1": "json1",
"json1Column2": "json1",
"json2Column1": "json2",
"json2Column2": "json2",
},
{
"json1Column1": "json1",
"json1Column2": "json1",
"json2Column1": "json2",
"json2Column2": "json2",
}
];