Siri G
Siri G

Reputation: 1

How to access data from object which is in JSON format

    { username: 'mn_admin',
      details:
              [ { appName: 'node',
                  pid: 5336,
                  starttime: '/Date(1509945756467)/',
                  endtime: '/Date(1509945868200)/',
                  appusage: 2,
                  username: 'mn_admin' } ] }

This is my data in JSON format. How do I access appName in it? I am using MEAN stack Also, I have tried to push the entire data into an array, but it didn't work. I tried to access data.details but that said its an undefined object. Let me know what I am doing wrong.

Upvotes: 0

Views: 38

Answers (1)

Tuan Anh Tran
Tuan Anh Tran

Reputation: 7237

if it's object, you can simply access it as myObj.details[0].appName. If not, you will have to parse it const myObj = JSON.parse(jsonString) first and then use it like above.

Upvotes: 1

Related Questions