1

I used the fetch api to take the json data from the api that I linked in the code. I then tried to parse the data and log the quote from the parsed data in the console.

fetch("https://api.breakingbadquotes.xyz/v1/quotes")
.then(data => data.json())
.then(data => {
    console.log(JSON.parse(data.quote));
});

This came up with the error "unexpected token o in JSON at position 1" in the console, meaning that the data is already parsed. So, logically, I removed the JSON.parse method from line 4 expecting the issue to be resolved.

fetch("https://api.breakingbadquotes.xyz/v1/quotes")
.then(data => data.json())
.then(data => {
    console.log(data.quote);
});

However, this simply appeared as undefined in the console, meaning that data has not been parsed. Can anyone explain what the issue here is exactly? I apologize in advance if I am missing something obvious, I am still a beginner to javascript and programming as a whole. Thank you!

VLAZ
  • 26,331
  • 9
  • 49
  • 67
rat182
  • 71
  • 1
  • 9
  • Try looking at the actual data. The response is an array, not an object. Try `data[0].quote` – Phil Jul 18 '22 at 03:52

0 Answers0