I fetch the data from an Api (Free Advice Api ) after fetching i convert the data into json format . but when I try to parse Json it through an error
VM3787:1 Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at index.js:24:18
My JS code
let url = ` https://api.adviceslip.com/advice`;
let convert = async() =>
{
try{
let takedata = await fetch(url).then(res => res.json()).then(data => {
console.log("Api fetched Successfully");
// console.log(data);
})
return takedata;
}
catch(e)
{
console.log(e);
}
}
// console.log(convert());//this provide data in console as Json format
//converting json into array
console.log(JSON.parse(convert()));