I try to parse this JSON object, but always got Cannot read property 'name' of undefined
JSON
{
"success": {
"name": "MY NAME"
}
}
JS
fetch("http://MYAPP/api/details")
.then(response => {
if (!response.ok) {
throw new Error("HTTP error " + response.status);
}
return response.text();
})
.then(data => {
console.log(data.success.name); // <= ERROR
})
.catch(error => {
console.error(error.message);
});