I'm trying to merge two JSON objects which contains arrays:
var data1 = '{"resourceType": "test", "entry": [{"foo": 123, "test":"foo"},{"foo": 456, "test":"abc"}]}';
var data2 = '{"resourceType": "test", "entry": [{"foo": 789, "test":"bar"},{"foo": 102, "test":"def"}]}';
var json1 = JSON.parse(data1);
var json2 = JSON.parse(data2);
var obj = $.extend({},json1,json2);
console.log(obj);
but what I'm getting is overwritten by data2 object when .concat will create an array with those two objects rather than wham I'm looking for is to get entry array of objects to be combined.
Desired results should be like:
{"resourceType": "test",
"entry": [
{"foo": 123, "test":"foo"},
{"foo": 456, "test":"abc"},
{"foo": 789, "test":"bar"},
{"foo": 102, "test":"def"}
]
}
Any tips on that?