I have two JSON strings that are constructed dynamically. The first one is created from an XML Document:
if (window.DOMParser) {
parser = new DOMParser();
xmlDoc = parser.parseFromString(xml_string, "text/xml");
} else// Internet Explorer
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(xml_string);
}
var json_str = xml2json(xmlDoc,"")
The other one created on the spot from user input.
Both have the same structure. The first one is:
{"Movies": { "Movie": [{"Title":"Movie1","Year":"2013"}]}};
and the second one is:
{"Movies": { "Movie": [{"Title":"Movie2","Year":"2014"}]}};
How can I concatenate these two so the result is two 'Movie' inside a "Movies": The result should be:
{"Movies": { "Movie": [{"Title":"Movie1","Year":"2013"},{"Title":"Movie2","Year":"2014"}]}};
I know that one method is to push {"Title":"Movie2","Year":"2014"} into ["Movies"]["Movie"] ... but is there any other way?