Similar Question:
Combining and sorting two json objects
I have a pair of JSON objects
[
{"name": "Graduation"},
{"name": "Post Graduation"}
]
and another one that is identical
[
{"name": "first sem"},
{"name": "second sem"},
{"name": "third sem"}
]
How can I merge these two JSON objects into one, like this:
[
{"name": "Graduation"},
{"name": "Post Graduation"},
{"name": "first sem"},
{"name": "second sem"},
{"name": "third sem"}
]
I attempted to do this using the following code:
_this.model = new qualification();
_this.model1 = new sems();
jsondata = _this.model.toJSON();
jsonData = _.extend(_this.model1.toJSON(),jsonData)
The resulting JSON has conflicting keys
I also tried
var result = _.union([jsonData1],[jsonData2]);
console.log(JSON.stringify(result));
Even when using concat, the output looks like this:
[{"0":{"name":"first sem"},"1":{"name":"second sem"},"2":{"name":"third sem"}},{"0":{"name":"Graduation"},"1":{"name":"Post Graduation"}}],