Sush
Sush

Reputation: 1457

get a json data key value in node.js

i have following json data.from this i need to extract os value. How it can be done using node.js

result = data.toString();

console.log(result) prints following

 [ { _id: '52849a7b8dd61980d1b49b87',          
        id: '70',           
        mode: 'daily',
        os: 'VM-WIN7-64',
        server: '172.16.2.120' } ]

i tried console.log(result.os); prints undefined!

How can i get os value

Upvotes: 0

Views: 4673

Answers (1)

James Allardice
James Allardice

Reputation: 165971

Assuming data is an array you should be able to do this:

console.log(data[0].os);

Why are you calling toString on data? That will return a string, which obviously isn't going to have an os property. You need to work with the actual data structure.

Upvotes: 2

Related Questions