Wednesday, December 27, 2017

Re: How to parse json and display it in CBV.

On Dec 27, 2017 1:02 PM, "tango ward" <> wrote:
Follow up question. Apologies for the continuation.

I tried integrating the API from OpenDOTA

my code:

import requests
import json

res = url.json()

when I typed in 'res' in my terminal, it returns a List of dictionaries. Now, is it possible to turn this list to a dictionary? Apologies for the confusion, I am confuse as well.

The terms you are looking for are serialization (converting Python objects to JSON) and deserialization (converting JSON to Python objects). 

If you're using requests, and you can successfully run the .json() method, then you successfully converted the JSON to a native Python structure. 

In this case, you are requesting a list of heroes, so you received a list back. You'll need to find the hero you want in the list using the standard methods of working with Python lists, access that element, and then you'll have access to the dict for that hero.

There is probably a way to get a single dict for a specific hero from the API, but I'm not familiar with their API structure. You'll need to revert to their API documentation to determine the correct URL structure.


You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment