I am currently building a web project using underscore.js. Currently I am facing the problem that api sends a JSON result (with Many root element) which doesn't get understood by underscore.js because it has many root element. that's why underscore.js reads all data of only first root element...(not all data)
json combine response
{
"API_Reply" : {
"Product" : [{
"child" : "NN3",
"type" : 3,
"name" : "No. 1 lounge - Terminal 3",
}
],
"API_Header" : {
"Request" : {
"token" : 514099508,
"key" : "abc",
"v" : 1,
"format" : "js",
"version" : "lite"
}
}
}
} {
"API_Reply" : {
"Product" : [{
"child" : "NN2",
"type" : 3,
"name" : "No. 1 lounge - Terminal 2",
}
],
"API_Header" : {
"Request" : {
"token" : 514099508,
"key" : "abc",
"v" : 1,
"format" : "js",
"version" : "lite"
}
}
}
} {
"API_Reply" : {
"Product" : [{
"child" : "NN2",
"type" : 3,
"name" : "No. 1 lounge - Terminal 2",
}
],
"API_Header" : {
"Request" : {
"token" : 514099508,
"key" : "abc",
"v" : 1,
"format" : "js",
"version" : "lite"
}
}
}
there are many root element(Api_Reply) and many tag(Product) ,i want to merge them into one...and Api_header section as it is same and repeating every time.
like below (one root element "Api_Reply" and all product details in one category "Product")
Required Json format
{
"API_Reply" : {
"Product" : [{
"child" : "NN3",
"type" : 3,
"name" : "No. 1 lounge - Terminal 3",
},{
"child" : "NN2",
"type" : 3,
"name" : "No. 1 lounge - Terminal 2",
}
},{
"child" : "NN2",
"type" : 3,
"name" : "No. 1 lounge - Terminal 2",
}
}],
"API_Header" : {
"Request" : {
"token" : 514099508,
"key" : "abc",
"v" : 1,
"format" : "js",
"version" : "lite"
}
}
}
Has someone a simple and understandable solution?