I want to combine two arrays containing json objects but keep the duplicate keys by prepending the keys with some text. In the example below the data from the object json2 is overwriting the object json1 because they have the same keys but I want to keep the data from the 1st object as well. Thanks.
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));
is returning
[
{
"Column1": "json2",
"Column2": "json2",
},
{
"Column1": "json2",
"Column2": "json2",
}
];
but I want
[
{
"json1Column1": "json1",
"json1Column2": "json1",
"json2Column1": "json2",
"json2Column2": "json2",
},
{
"json1Column1": "json1",
"json1Column2": "json1",
"json2Column1": "json2",
"json2Column2": "json2",
}
];
'json1'to all of the members ofjson1, and doing the same forjson2, before merging them?