I get a JSON String as a result from an API that looks like this:
{
"batchcomplete": "",
"query": {
"pages": {
"682482": {
"pageid": 682482,
"ns": 0,
"title": "Human",
"thumbnail": {
"source": "https://upload.wikimedia.org/wikipedia/commons/thumb/6/68/Akha_cropped_hires.JPG/119px-Akha_cropped_hires.JPG",
"width": 119,
"height": 200
},
"extract": "Humans (Homo sapiens) are a species of highly intelligent primates. They are the only extant members of the subtribe Hominina and—together with chimpanzees, gorillas, and orangutans—are part of the family Hominidae (the great apes, or hominids). Humans are terrestrial animals, characterized by their erect posture and bipedal locomotion; high manual..."
}
}
}
}
The goal
I never know what the pageid will be and I need to retrieve the extract and thumbnail.
The extract should be a String and the thumbnail an Object.
Wouldn't be much of an issue if it weren't for the random pageid.
What I've tried
const thumbnail = jsonObj.query[0].thumbnail;
const extract = jsonObj.query[0].extract;
Expected result
thumbnail = {
"source": "https://upload.wikimedia.org/wikipedia/commons/thumb/6/68/Akha_cropped_hires.JPG/119px-Akha_cropped_hires.JPG",
"width": 119,
"height": 200
}
extract = "Humans (Homo sapiens) are a species of highly intelligent primates. They are the only extant members of the subtribe Hominina and—together with chimpanzees, gorillas, and orangutans—are part of the family Hominidae (the great apes, or hominids). Humans are terrestrial animals, characterized by their erect posture and bipedal locomotion; high manual...";