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

216
Views
How to parse JSON in node js

I have this JSON array, and what I want is to get the password field alone

var user = [ { _id: 5902086ecbc0dd11e4870fd9,
    password: '$2a$08$FIpkmFT1WDZggQYyBA4CVuop6pelbKBfUEJ1/KAVIV2Si9Ho1EYhi',
    email: 'jv100@gmail.com',
    lastName: 'v',
    firstName: 'j',
    updatedDate: 2017-04-27T15:04:14.483Z,
    createdDate: 2017-04-27T15:04:14.483Z } ]

I tried to parse it using this code

var obj = JSON.parse(user);
console.log(user.password);

but still it is undefined.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

User is already a list of objects, so you don't need to parse it. However, it is an array. So if you meant for it to be an array, you'd need to access the password by using this code:

console.log(user[0].password);
over 4 years ago · Santiago Trujillo Report

0

It's already an array there is nothing to parse. You can access your property via :

console.log(user[0].password);

You can't access your property with user.password because user variable is not object, it's an array, your object is stored at the zero index of your array.

over 4 years ago · Santiago Trujillo Report

0

You already have JSON object. hence, no need to parse it again.

DEMO

var user = [{ _id: "5902086ecbc0dd11e4870fd9",
    password: '$2a$08$FIpkmFT1WDZggQYyBA4CVuop6pelbKBfUEJ1/KAVIV2Si9Ho1EYhi',
    email: 'jv100@gmail.com',
    lastName: 'v',
    firstName: 'j',
    updatedDate: "2017-04-27T15:04:14.483Z",
    createdDate: "2017-04-27T15:04:14.483Z" } ];
    
var password = user[0].password;

console.log(password);

over 4 years ago · Santiago Trujillo 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!