Vishnu Shanmughan
Vishnu Shanmughan

Reputation: 101

How to Convert a named json array to un named array

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

Answers (2)

Jack jdeoel
Jack jdeoel

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

Muhammad Usman
Muhammad Usman

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

Related Questions