user2874270
user2874270

Reputation: 1382

Retrieving values from multidimensional JSON object in Javascript

This is probably a really stupid question, but I'm getting a JSON object returned by an API call and I can't for the life of me figure out how to get the values out of it. After I make the call, I pretty print the JSON object and it shows the following:

 [
  {
    "link_request": {
      "success": true,
      "link": "https://www.blah.com"
    },
    "errors": null
  }
]

I want to be able to get at that link value. I've tried both of the following, but neither works.

var link = data.query.link;

var link = data['query']['link']

Any help? Thanks!

Upvotes: 1

Views: 1370

Answers (2)

Sumit
Sumit

Reputation: 103

Use the below code to get link:

jsonArray = [ {
    "link_request": {
      "success": true,
      "link": "https://www.blah.com"
    },
    "errors": null
    }
];
console.log(jsonArray[0].link_request.link)

Upvotes: 0

Suraj Rawat
Suraj Rawat

Reputation: 3763

Here it is

obj[0].link_request.link

Upvotes: 3

Related Questions