Is there an easy way to see the data extracted from an API?

Screen Link: https://app.dataquest.io/m/110/challenge%3A-working-with-the-reddit-api/5/getting-the-most-upvoted-comment

I was wondering if there’s a way to see the data with indetation, like a proper json file instead of a list with a bunch of values that is imposible to understand and find anything.

To make myself clearer, is posible to show this
“[{‘kind’: ‘Listing’, ‘data’: {‘after’: None, ‘children’: [{‘kind’: ‘t3’, ‘data’: {‘secure_media’: None, ‘approved_by’: None, ‘media’: None, ‘archived’: False, ‘score’: 55, ‘locked’: False, ‘clicked’: False, ‘title’: ‘Functional Philosophy and applying it to Python’, ‘selftext_html’: None, ‘is_self’: False, ‘thumbnail’: ‘’, ‘created’: 1458515741.0, ‘edited’: False, ‘report_reasons’: None, ‘author_flair_text’: None, ‘id’: ‘4b7w9u’, ‘saved’: False, ‘visited’: False, ‘suggested_sort’: None, ‘url’: ‘http://hkupty.github.io/2016/Functional-Programming-Concepts-Idioms-and-Philosophy/’, ‘subreddit_id’: ‘t5_2qh0y’, ‘hidden’: False, ‘num_reports’: None, ‘removal_reason’: None, ‘from’: None, ‘subreddit’: ‘Python’, ‘from_id’: None, ‘banned_by’: None, ‘mod_reports’: , ‘user_reports’: , ‘media_embed’: {}, ‘link_flair_css_class’: None, ‘downs’: 0, ‘distinguished’: None, ‘upvote_ratio’: 0.87, ‘name’: ‘t3_4b7w9u’, ‘quarantine’: False, ‘author’: ‘ingvij’, ‘stickied’: False, ‘domain’: ‘hkupty.github.io’, ‘num_comments’: 13, ‘likes’: None, ‘gilded’: 0, ‘author_flair_css_class’: None, ‘hide_score’: False, ‘ups’: 55,…” in a clearer way?

Thanks for your help

3 Likes

Hello @alegiraldo666 that is possible. This is known as Pretty printing: , json.dumps has an argument indent which by default is None, you can assign indent=4 in json.dumps to prettify your json

print(json.dumps(json_data, indent=4, sort_keys=True))

If indent is a non-negative integer or string, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0, negative, or "" will only insert newlines. None (the default) selects the most compact representation. Using a positive integer indent indents that many spaces per level. If indent is a string (such as "\t" ), that string is used to indent each level.

More resources:


https://docs.python.org/3/library/json.html#basic-usage
4 Likes