Reputation: 101
I need to convert following json array
{
"employees": [{
"firstName": "John",
"lastName": "Doe"
}, {
"firstName": "Anna",
"lastName": "Smith"
}, {
"firstName": "Peter",
"lastName": "Jones"
}]
}
to a json array without name 'Employee'
{[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
using javascript
Upvotes: 0
Views: 51
Reputation: 4584
Simply can do ,
var arr ={"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]};
var employee = arr.employees;
console.log(employee);
Upvotes: 1
Reputation: 1362
try this one
var employeeArr = {"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
var emp = $.each(employeeArr.employees, function(index , value){
return value;
},{})
console.log(emp);
Upvotes: 1