Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
How to get particular data values from JSON Node.js?

This is my JSON file output:

let employees = [{
  "id":1,
  "name":"Lann",
  "username":"brot",
  "email":"b@sd.com",
  "address": {
    "city":"Gweh",
    "zipcode":"92998-3874",
    "geo": {
      "lat":"45",
      "lng":"77"
    }
  }
}]

How I get id, name and email from that like below:

{
  "id":1,
  "name":"Lann",
  "email":"b@sd.com"
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can archive using map.

let employees = [{
          "id":1,
          "name":"Lann",
          "username":"brot",
          "email":"b@sd.com",
          "address":{
             "city":"Gweh",
             "zipcode":"92998-3874",
             "geo":{
                "lat":"45",
                "lng":"77"
             }
          }
          }]
const data = employees.map(o => ({ id: o.id, name: o.name, email:o.email }));
console.log(data[0]);

about 4 years ago · Juan Pablo Isaza Report

0

If your array has only one element you can just access the info, no need to build another array like this: employees[0].id , employees[0].name, employees[0].email or you can just extract an object using Object Destructuring

let employees = [{
  "id": 1,
  "name": "Lann",
  "username": "brot",
  "email": "b@sd.com",
  "address": {
    "city": "Gweh",
    "zipcode": "92998-3874",
    "geo": {
      "lat": "45",
      "lng": "77"
    }
  }
}];
const picked = (({ id, name, email }) => ({  id, name, email }))(employees[0]);
console.log(picked);

but if your array has more employees, i think what you need to do is search by id or name and get back just an object with minimal info, you can do that like this

let employees = [{
  "id": 1,
  "name": "Lann",
  "username": "brot",
  "email": "b@sd.com",
  "address": {
    "city": "Gweh",
    "zipcode": "92998-3874",
    "geo": {
      "lat": "45",
      "lng": "77"
    }
  }
}];
let employee = employees.find(o => o.name === 'Lann');
let picked = (({ id, name,email }) => ({ id, name,email }))(employee);
console.log(picked);

about 4 years ago · Juan Pablo Isaza Report

0

You can simply do this by using array destructuring.

let employees = [{
          "id":1,
          "name":"Lann",
          "username":"brot",
          "email":"b@sd.com",
          "address":{
             "city":"Gweh",
             "zipcode":"92998-3874",
             "geo":{
                "lat":"45",
                "lng":"77"
             }
          }}];

// Destructuring array
const [employee] = employees;

** Now from here employee is an object and you can access its property normally as you do with other objects. For getting id, name, username:**

employee.id;
employee.name;
employee.username;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!