I want to bring back the age property from the JSON created by the API but it throws this error:
SyntaxError:JSON.parse: unexpected character at line 1 column 2 of the JSON data
The console.log(await response.json()) gives me all my JSON data, but when I comment it out and put the last code line, this error occurs.
I was told to try one of these:
response.json()["age"]response.json()[age]response.json().agelet json = JSON.parse(response);
console.log(json["age"]) was close, but not successful.
let table = base.getTable("test");
let view = table.getView("Donnée brut");
let age;
let query = await view.selectRecordsAsync({
sorts: [
// sort by "Prénom" in ascending order...
{
field: "Prénom"
}
]
});
// print ID & "Prénom" from each record:
for (let record of query.records) {
let name = (record.getCellValueAsString('Prénom'));
var response = await fetch('https://api.agify.io/?name=' + name);
/* console.log(await response.json()); */
let json = JSON.parse(await response.json());
console.log(json["age"]);
}
response.json()andresponse.text()?(await response.json())["age"]or(await response.json()).ageorconst data = await response.json(); console.log(data.age)