extract a specific value in nested json using python

If there’s is only one key each time you can just extract the page number like this:

page = list(data['query']['pages'])[0]
print(data['query']['pages'][page]['extract'])

If there is more than one you could just get the list using keys() and then loop them like this:

pages = list(data['query']['pages'].keys())
for page in pages:
    print(data['query']['pages'][page]['extract'])
    

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top