How to merge two JSON data in javascript / JQUERY -


i want merge 2 json data using javascript or jquery.

var object1 = [{     "id": 11,     "name": "vasanth",     "username": "vasanth.rajendran",     "email": "vasanth@mail.com",     "address": {       "street": "nungampakkam",       "suite": "no154",       "city": "chennai",       "zipcode": "31428-2261",       "geo": {         "lat": "-38.2386",         "lng": "57.2232"       }     },     "phone": "024-648-3804",     "website": "google.net",     "company": {       "name": "test",       "catchphrase": "centralized empowering task-force",       "bs": "target end-to-end models"     }   }];  var object2 = [{     "id": 2,     "name": "raju",     "username": "raju.rajendran",     "email": "raju@mail.com",     "address": {       "street": "nungampakkam",       "suite": "no154",       "city": "chennai",       "zipcode": "31428-2261",       "geo": {         "lat": "-38.2386",         "lng": "57.2232"       }     },     "phone": "024-648-3804",     "website": "google.net",     "company": {       "name": "test",       "catchphrase": "centralized empowering task-force",       "bs": "target end-to-end models"     }   }]; 

example result:

[   {     "id": 1,     "name": "leanne graham",     "username": "bret",     "email": "sincere@april.biz",     "address": {       "street": "kulas light",       "suite": "apt. 556",       "city": "gwenborough",       "zipcode": "92998-3874",       "geo": {         "lat": "-37.3159",         "lng": "81.1496"       }     },     "phone": "1-770-736-8031 x56442",     "website": "hildegard.org",     "company": {       "name": "romaguera-crona",       "catchphrase": "multi-layered client-server neural-net",       "bs": "harness real-time e-markets"     }   },   {     "id": 2,     "name": "ervin howell",     "username": "antonette",     "email": "shanna@melissa.tv",     "address": {       "street": "victor plains",       "suite": "suite 879",       "city": "wisokyburgh",       "zipcode": "90566-7771",       "geo": {         "lat": "-43.9509",         "lng": "-34.4618"       }     },     "phone": "010-692-6593 x09125",     "website": "anastasia.net",     "company": {       "name": "deckow-crist",       "catchphrase": "proactive didactic contingency",       "bs": "synergize scalable supply-chains"     }   }]; 

object1 , object2 arrays. can use concat method concatenate arrays.

newobj = object1.concat(object2); 

var object1 = [{      "id": 11,      "name": "vasanth",      "username": "vasanth.rajendran",      "email": "vasanth@mail.com",      "address": {        "street": "nungampakkam",        "suite": "no154",        "city": "chennai",        "zipcode": "31428-2261",        "geo": {          "lat": "-38.2386",          "lng": "57.2232"        }      },      "phone": "024-648-3804",      "website": "google.net",      "company": {        "name": "test",        "catchphrase": "centralized empowering task-force",        "bs": "target end-to-end models"      }    }];    var object2 = [{      "id": 2,      "name": "raju",      "username": "raju.rajendran",      "email": "raju@mail.com",      "address": {        "street": "nungampakkam",        "suite": "no154",        "city": "chennai",        "zipcode": "31428-2261",        "geo": {          "lat": "-38.2386",          "lng": "57.2232"        }      },      "phone": "024-648-3804",      "website": "google.net",      "company": {        "name": "test",        "catchphrase": "centralized empowering task-force",        "bs": "target end-to-end models"      }    }];    var newobject = object1.concat(object2);  console.log(newobject);


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -