I have a JSON object with the following content:
[
{
\"_id\":\"5078c3a803ff4197dc81fbfb\",
\"email\":\"user1@gmail.com\",
\"image\":\"some_imag
If you want to do it dynamically, for example, you have an array which you want to apply as a key to JSON object:
your Array will be like :
var keys = ["id", "name","Address","Phone"] // The array size should be same as JSON Object keys size
Now you have a JSON Array like:
var jArray = [
{
"_id": 1,
"_name": "Asna",
"Address": "NY",
"Phone": 123
},
{
"_id": 2,
"_name": "Euphoria",
"Address": "Monaco",
"Phone": 124
},
{
"_id": 3,
"_name": "Ahmed",
"Address": "Mumbai",
"Phone": 125
}
]
$.each(jArray ,function(pos,obj){
var counter = 0;
$.each(obj,function(key,value){
jArray [pos][keys[counter]] = value;
delete jArray [pos][key];
counter++;
})
})
Your resultant JSON Array will be like :
[
{
"id": 1,
"name": "Asna",
"Address": "NY",
"Phone": 123
},
{
"id": 2,
"name": "Euphoria",
"Address": "Monaco",
"Phone": 124
},
{
"id": 3,
"name": "Ahmed",
"Address": "Mumbai",
"Phone": 125
}
]