1

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!

2
  • The root value is an Array. You can access the Object within it using an index -- data[0]. And, the other Object within that by one of its properties -- data[0].link_request. Etc. (Access / process (nested) objects, arrays or JSON) Commented Aug 10, 2015 at 4:17
  • Also keep in mind, if you are getting a string, parse it into an object via JSON.parse and then use access its properties. Commented Aug 10, 2015 at 4:25

2 Answers 2

3

Here it is

obj[0].link_request.link
Sign up to request clarification or add additional context in comments.

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.